angular ディレクティブの更新/更新で問題が発生しています。基本的に、サーバーへの非同期呼び出しを行うフラグボタンがあり、成功した場合は、ボタンを無効にし、テキストを「フラグ付き...」に変更するプロパティuserFlagsを変更します。
ディレクティブは次のとおりです。
app.directive('flagable', function() {
return {
restrict: 'E',
scope: { item: '=' },
templateUrl: '/Content/templates/flagable.tmpl',
controller: function($scope) {
$scope.flag = function () {
$scope.$apply(function () {
// ITS NOT GOING IN HERE!
//AJAX CALL HERE
model.$modelValue.userFlags = [];
Messenger().post("Your request has succeded! ");
});
};
}
};
});
テンプレートは次のとおりです。
<div class="btn-group pull-right">
<button class="btn btn-small btn-danger" ng-disabled="{{item.userFlags != null}}"><i class="icon-flag"></i>
<any ng-switch="item.userFlags==null">
<any ng-switch-when="true">Flag</any>
<any ng-switch-when="false">Flagged...</any>
</any>
</button>
<button class="btn btn-small btn-danger dropdown-toggle" data-toggle="dropdown" ng-disabled="{{item.userFlags != null}}"><span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#" ng-click="flag()">Inappropriate</a></li>
<li><a href="#" ng-click="flag()">Overpost</a></li>
<li><a href="#" ng-click="flag()">Spam</a></li>
</ul>
</div>
興味深いことに、コントローラーのロジックを次のように変更します。
$scope.flag = function () {
$scope.item.userFlags = [];
Messenger().post("Your request has succeded! " + $scope.item.viewCount);
};
ボタンが「フラグ付き...」に適切に更新される原因ですが、ng-disabled はボタンを無効にしません! firebug では、ng-disabled プロパティが設定されていることを示しています: ng-disabled="true"