我有数据列表并使用ng-repeat来显示它们
<div class="modal-body">
<input class="form-control input-lg" type="text" ng-model="providerPicked" placeholder="Cari Produk">
<div class="button-search-result">
<div ng-repeat="Provider in Providers">
<button type="button" class="btn btn-default btn-lg" ng-click="pickProvider(Provider)" ng-show="Provider.IsActive">{{ Provider.Name}}</button>
<button type="button" class="btn btn-default btn-lg" ng-click="inactive()" ng-show="!Provider.IsActive">{{ Provider.Name}}</button>
</div>
</div>
</div>
这是我的控制器
$scope.pickProvider = function (Provider) {
console.log('pickProvider')
};
$scope.inactive = function () {
console.log('inactive')
};
我不明白的是, 我的pickProvider(提供商)工作正常,但我的非活动()根本没有吵架,请有人可以帮我这个
答案 0 :(得分:1)
我用你的代码做了一个快速的plunker(虽然跳过了模态)。
<body ng-app="app">
<div ng-controller="MyCtrl">
<input class="form-control input-lg" type="text" ng-model="providerPicked" placeholder="Cari Produk">
<div class="button-search-result">
<div ng-repeat="Provider in Providers">
<button type="button" class="btn btn-default btn-lg" ng-click="pickProvider(Provider)" ng-show="Provider.IsActive">{{ Provider.Name}}</button>
<button type="button" class="btn btn-default btn-lg" ng-click="inactive()" ng-show="!Provider.IsActive">{{ Provider.Name}}</button>
</div>
</div>
</div>
</body>
在script.js中:
var app = angular.module('app',[]);
app.controller('MyCtrl', ['$scope',
function ($scope) {
$scope.Providers = [
{ Name: "AAA", IsActive: true },
{ Name: "BBB", IsActive: true },
{ Name: "CCC", IsActive: false },
{ Name: "DDD", IsActive: true },
{ Name: "EEE", IsActive: false }
];
$scope.pickProvider = function (Provider) {
console.log('pickProvider');
};
$scope.inactive = function () {
console.log('inactive');
};
}]);
我不会在您发布的代码中考虑问题,但无论是在模式中还是在您在$ scope.Providers中获得的任何内容中。我不太确定,因为它对我来说很好。控制台输出说:
inactive
pickProvider
inactive