我想加载并将参数传递给ng-include。
当用户点击按钮时,它想要用另一个参数重新加载相同的ng-include。
现在不行。任何想法如何使这项工作?
这是代码:http://plnkr.co/edit/marR00jw2k2EU2Rp3QR6
html:
<div ng-controller="ListCtrl">
<button class="btn" type="button" ng-click="loadList(A)">A</button>
<button class="btn" type="button" ng-click="loadList(B)">B</button>
<div ng-include="'tplList.html'" onload="loadList(0)"></div>
</div>
js:
angular.module('myApp', ['myApp.services', 'myApp.controllers']);
angular.module('myApp.services', ['ngResource']).
factory('List0', function($resource){
return $resource('list0.json');
}).
factory('List1', function($resource){
return $resource('list1.json');
}).
factory('List2', function($resource){
return $resource('list2.json');
});
angular.module('myApp.controllers', []).
controller('ListCtrl', ['$scope', 'List1', 'List2', function($scope, List1, List2) {
$scope.loadList = function (param) {
if (param === 'A') {
$scope.elms = List1.query();
} else if (param === 'B') {
$scope.elms = List2.query();
} else {
$scope.elms = List0.query();
}
}
}]);
答案 0 :(得分:1)
你快到了,你需要将A
,B
作为字符串传递
<button class="btn" type="button" ng-click="loadList('A')">load list 1</button>
<button class="btn" type="button" ng-click="loadList('B')">load list 2</button>