0

我想加载参数并将其传递给 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();
        }
    }
}]);
4

1 回答 1

1

你快到了,你需要通过AB像这样的字符串

<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>
于 2013-07-31T19:12:41.483 回答