我正在尝试处理我的项目并构建角度控制器以保存两个不同页面的数据。
第一页上的代码是......
<div ng-app="app">
<div ng-controller="shopItemController">
<div class="itm" ng-repeat="shopItem in shopItems">
<div class="imag"></div>
<h2>{{ shopItems.name }}</h2>
<div class="hf">Buy it: {{ shopItems.price }}</div>
<div class="hff">Earn it: {{ shopItems.altprice }}</div>
<div class="desc"><div>{{ shopItems.desc }}</div></div>
<div class="prog"><div>{{ shopItems.progress }}</div></div>
</div>
</div>
</div>
......第二页就在这里。
<div ng-app="app">
<div ng-controller="trophyEarnsController">
<div class="itm" ng-repeat="trophyEarn in trophyEarns">
<div class="imag"></div>
<h2> {{ trophyEarns.name }} </h2>
<!--<div class="hf">Buy it: {{ trophyEarns.price }}</div>
<div class="hff">Earn it: {{ trophyEarns.altprice }}</div>-->
<div class="desc"><div> {{ trophyEarns.desc }} </div></div>
<div class="prog"><div> {{ trophyEarns.progress }} </div></div>
</div>
</div>
</div>
这是我的控制器
var shopItems = angular.module('shopItems', []);
var trophyEarns = angular.module('trophyEarns', []);
var app = angular.module('app', ['shopItems', 'trophyEarns']);
shopItems.controller('shopItemController', function ($scope) {
$scope.shopItems = [{
//id: 01,
name: 'One',
//img: '',
price: '$3.99',
altprice: '1 mile',
desc: 'This is a fake description.',
prog: '50%'
},{
//id: 02,
name: 'Two',
//img: '',
price: '$3.99',
altprice: '1 mile',
desc: 'This is a fake description.',
prog: '50%'
}];
});
trophyEarns.controller('trophyEarnsController', function ($scope) {
$scope.trophyEarns = [{
//id: 01,
name: 'One',
//img: '',
price: '$3.99',
altprice: '1 mile',
desc: 'This is a fake description.',
prog: '50%'
},{
//id: 02,
name: 'Two',
//img: '',
price: '$3.99',
altprice: '1 mile',
desc: 'This is a fake description.',
prog: '50%'
}];
});
这是我第一次独自写这篇文章。它适用于我的小提琴。
http://jsfiddle.net/galnova/rfg80gye/28/
但是当我改变它并尝试将另一个控制器添加到controller.js时,它就崩溃了。
欢迎任何帮助。这可能需要至少一周的时间来修复我自己。