我正在使用Angular.js創建應用程序,但我的index.html文件似乎沒有訪問我的controller.js文件。瀏覽器打印出像這樣在大括號中的變量:{{} friend.name},{{friend.number}}如何訪問Angular.js中的控制器
這裏是我的html文件:
<!DOCTYPE HTML>
<html ng-app>
<head>
<title>Angular Directives</title>
</head>
<body>
<div class="container" ng-controller="demoController">
<h1>Angular Directives</h1>
<h2>ng-model example: two-way binding and $scope</h2>
<h3>Name</h3>
<input type="text" ng-model="name">
<br />
Hello, {{name}}!
<h2>ng-repeat example</h2>
<ul>
<li ng-repeat="friend in friends">{{friend.name}}, {{friend.number}}</li>
</ul>
</div>
</body>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
<script src = "controller.js"></script>
</html>
這是我的controller.js文件:
var demoController = function($scope) {
$scope.name = "John Doe";
var friend1 = {
name: "Tim Thompson",
number: "111-111-1111"
};
var friend2 = {
name: "Sally Smith",
number: "222-222-2222"
};
var friend3 = {
name: "Billy Bob",
number: "333-333-3333"
};
var friends = [friend1, friend2, friend3];
$scope.friends = friends;
}
你正在使用哪種角度版本?或任何控制檯錯誤? – Vineet
在ng-app中輸入你的模塊名稱 –