我m just starting out with AngularJS and I
我遇到了这段代码的问题。
这是我的js文件中名为cribsController.js的代码:
angular
.module('ngCribs')
.controller('cribsController', function($scope) {
$scope.hello = 'Hello world!';
});
这是我的HTML:
<html>
<head>
<meta charset="utf-8" />
<title>ng-cribs</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
</head>
<body ng-app="ngCribs" ng-controller="cribsController">
<h1>{{hello}}</h1>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.2/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/1.2.5/ui-bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/1.2.5/ui-bootstrap-tpls.min.js"></script>
<script src="app.js"></script>
<script src="scripts/cribsController.js"></script>
当我查看html文件,而不是显示Hellow world!时,我得到{{hello}}。
我在这里做错了什么?
答案 0 :(得分:0)
我所做的只是将代码包装在函数调用中。
(function(angular) {
'use strict';
angular.module('ngCribs', [])
.controller('cribsController', function($scope){
$scope.hello = 'Hello';
});
})(window.angular);