您好我已经开始学习Angular.js了,这是我的第一个活动。这一切都很好但是当我将ng-controller添加到body元素时它不起作用。我被困在这里你能告诉我这里有什么问题吗?
<html ng-app="helloWorldApp">
<head>
<title>Angular Fundamentals</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7"
crossorigin="anonymous">
</head>
<body ng-controller="firstController">
<div class="container">
<h1>AngularFundamentals</h1>
<h2> {{'Hello World from Angular'}}</h2>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
<script>
var helloWorldApp = angular.module('helloWorldApp',[]);
helloWorldApp.controller('firstController',[ '$scope', function(scope){
$scope.appName =" An App Name";
}]);
</script>
</body>
</html>
答案 0 :(得分:0)
你需要
<h2>{{appName}}</h2>
<强>样本强>
var helloWorldApp = angular.module('helloWorldApp',[]);
helloWorldApp.controller('firstController',['$scope', function($scope){
$scope.appName =" An App Name";
}]);
&#13;
<html ng-app="helloWorldApp">
<head>
<body ng-controller="firstController">
<div class="container">
<h1>AngularFundamentals</h1>
<h2> {{appName}}</h2>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
&#13;