我添加了模块和 Controller ,但它不起作用。请指出我的错误,以便我删除它们。
var app=angular.module("hello",[]);
app.controller("func",function()
{
this.products=gems;
});
var gems=[
name:Azhar,
gpa:2.8,
institute:UCP
];
**html code**
//html code of what I have done so far.
<script src="angular.min.js"></script>
<script src="world.js"></script>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css" />
<html>
<body ng-app="hello">
<div ng-controller="func">
{{products.name}};
</div>
</body>
</html>
最佳答案
我已经更正了您的代码:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<script src="angular.min.js"></script>
<script src="world.js"></script>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body ng-app="hello">
<div ng-controller="func">
{{products.name}}
</div>
</body>
</html>
JavaScript
var app = angular.module("hello", []);
app.controller("func", ['$scope', function ($scope) {
var gems = {
name: 'Azhar',
gpa: 2.8,
institute: 'UCP'
};
$scope.products = gems;
}]);
关于javascript - angularjs 在我的代码中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39225935/