我已經搜索並閱讀所有可能的解釋,但目前爲止沒有任何幫助。 問題是與大括號的數據綁定不起作用(只有在我在index.html中定義模塊和控制器時才起作用)。簡單的AngularJS控制器不起作用
的index.html:
<html lang="en" data-ng-app="myApp">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="css/main.css" media="screen">
<script src="controllers/listcontroller.js"></script>
<script src="js/app.js"></script>
<script data-require="[email protected]*" data-semver="2.0.0" src="https://code.angularjs.org/1.3.0-beta.5/angular.js"></script>
</head>
<div class="main">
<body data-ng-controller="ListController">
<ul>
<li data-ng-repeat="test in tests">
<span>{{ test.name }}</span>
<p>{{ test.type }}</p>
</li>
</ul>
There are currently {{test.length}} tests available.
You have currently selected 0 tests.
<button class="animatedbutton"> Proceed </button>
</div>
</body>
</html>
app.js(在文件夾中的js):
(function() {
'use strict';
angular.module('myApp', ['myApp.controller']);
})();
listcontroller.js(在文件夾中的控制器):
(function() {
'use strict';
var app = angular.module('myApp.controller');
app.controller('ListController', ['$scope', function ($scope) {
$scope.tests = [
{'name': 'A',
'type': '1'},
{'name': 'B',
'type': '2'},];
}]);
})();
視圖顯示我這樣的事情:
{{ test.name }}
{{ test.type }}
目前
{{test.length}}
可用的測試。 您當前選擇了0個測試。
我遵循了一些教程,如60分鐘的角度,AngularJS.org和一些YT,但我總是遇到同樣的問題。有任何想法嗎?
做了一些改變,但更好的是你檢查重拳 – thegio
你真了不起!謝謝 :) – YaeVo