我在同一个应用程序中有两个控制器,但似乎只有一个被注册:
var app = angular.module('MyModule', []);
app.controller('FruitCtrl', function($scope) {
$scope.fruits = ['apples', 'oranges', 'bananas'];
});
app.controller('VegetableCtrl', function($scope) {
$scope.vegetables = ['potato', 'beans', 'onions'];
});
我的模板:
<div ng-app="MyModule">
<div ng-controller="FruitCtrl">
<div ng-repeat="fruit in fruits">{{fruit}}</div>
</div>
<div controller="VegetableCtrl">
<div ng-repeat="vegetable in vegetables">{{vegetable}}</div>
</div>
</div>
只有&#34;水果&#34;部分正在呈现。
答案 0 :(得分:3)
controller="VegetableCtrl"
应该是
ng-controller="VegetableCtrl"
答案 1 :(得分:2)
你错过了蔬菜重复的ng-controller控制器
http://jsfiddle.net/9wfhsgqf/3/
<div ng-app="MyModule">
<div ng-controller="VegetableCtrl">
<div ng-repeat="vegetable in vegetables">{{vegetable}}</div>
</div>
<div ng-controller="FruitCtrl">
<div ng-repeat="fruit in fruits">{{fruit}}</div>
</div>
答案 2 :(得分:1)
从
改变<div controller="VegetableCtrl">
到
<div ng-controller="VegetableCtrl">
答案 3 :(得分:1)
替换
<div controller="VegetableCtrl">
带
<div ng-controller="VegetableCtrl">
答案 4 :(得分:1)
你错过了&#39; ng - &#39;从第二个div开始,它应该是&#39; ng-controller&#39;不只是控制器