[英]AngularJs and ng-controller
I have just started learning AngularJS but I am stuck at this point. 我刚刚开始学习AngularJS,但现在还停留在这里。 I made three files in one project: 我在一个项目中制作了三个文件:
1.Index.html
2.Angular.min.js( downloaded from official site)
3.Script.js
But when I am opening html in browser I am not getting the value of test property. 但是,当我在浏览器中打开html时,我没有得到test属性的值。 It just shows the {{test}}
(not the value). 它仅显示{{test}}
(而不是值)。 Will be very thankful if you help me out. 如果您能帮助我,将非常感激。
<!DOCTYPE html>
<html lang="en" ng-app = "myapp">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body ng-controller = "MyCtrl">
{{test}}
<script src = "angular.min.js"</script>
<script src = "script.js"></script>
</body>
</html>***
Script.js file is Script.js文件是
var app = angular.module('myapp',[]);
app.controller('MyCtrl', ['$scope', function($scope){
$scope.test = "Welcome to my world";
}]);
Check the network tab be sure angular itself is actually loading copying and pasting your code into a running sample. 检查网络选项卡,确保angular本身实际上正在加载复制并将代码粘贴到正在运行的示例中。
var app = angular.module('myapp',[]); app.controller('MyCtrl', ['$scope', function($scope){ $scope.test = "Welcome to my world"; }]);
<!DOCTYPE html> <html lang="en" ng-app = "myapp"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body ng-controller = "MyCtrl"> {{test}} <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js"></script> <!-- you were missing a > here <script src = "angular.min.js"</script> <script src = "script.js"></script> --> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.