Я создаю приложение, использующее 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 введите имя модуля ur –