我有一個指令,應該允許我更改特定的模式,並更新範圍。如果條件爲真,則隱藏元素
這工作正常。
我現在面臨的問題是我需要能夠隱藏當前模式的元素。
我會更好地解釋它:
我有模式陣列:
[1,2,3,4,5]
和NG-中繼器裏面的一些鏈接:
<a href=""
ng-repeat="m in zoneModes"
ng-click="changeZoneMode({{m}})"
id="{{m}}"
class="menu-item">
<i class="icon-mode-{{m}}"></i>
</a>
什麼,我要做的就是躲元素如果selectedZone不等於m:
ng-if="selectedMode!=m"
接縫像一切都很好,但事實並非如此。
你可以清楚地看到什麼是從this live example
基本問題,每次的條件是滿足,它移除元素,從來沒有把它放回去。
我也試圖與NG-秀,但結果也不好,因爲它留下的空白點(你可以檢查this other example)
有什麼建議?由於
編輯
試圖使用過濾器的建議,但沒有運氣:
.directive('mySelector', function() {
var changeMode, linkFunction;
changeMode = function(newmode) {
var $scope;
$scope = this.$parent;
$scope.selectedMode = newmode;
$('.menu-open').attr('checked', false);
};
linkFunction = function(scope, element, attrs) {
scope.changeMode = changeMode;
scope.changeZoneMode = changeMode;
scope.zoneModes = [1, 2, 3, 4, 5];
return scope.$watch((function() {
return scope.selectedMode;
}), function(newMode) {
return scope.selectedMode = newMode;
});
};
return {
restrict: 'E',
scope: {
selectedMode: '=currentmode',
id: '@id'
},
replace: true,
templateUrl: 'templates/template.html',
link: linkFunction,
controller: 'abc'
};
}).controller('abc', ['$scope', function($scope) {
$scope.checkM = function (mode, m) {
return mode == m;
};
}])
template.html
<a href=""
ng-repeat="m in zoneModes|filter:checkM(selectedMode,m)"
ng-click="changeZoneMode({{m}})"
id="{{m}}"
class="menu-item">
<i class="icon-mode-{{m}}"></i>
</a>
除了當我改變模式(例如從1到2),我不想要顯示2,但我想要1被添加...基本上應該總是有4個圖標(四種不同的模式),但缺少的應該是選擇的 – Nick
如果我選擇Facebook,我想能夠看到twitter,twich,vine和vk,如果我選擇twitter,我想能夠看facebook,twich,vine,vk等。 – Nick
我試過了Jordan.JD的解決方案,我想這正是你想要的。 –