2015-10-16 54 views
0

我在主頁上有一個鏈接到另一個頁面的按鈕。點擊該按鈕時,我想從一個div中刪除類。單擊事件時,Ng級刪除類

控制器:

$scope.myClass = ["container","gnc1"]; 
    $scope.removeClass = function() { 
    $scope.myClass.splice(1, 2); 
} 

我使用的UI的路由器這樣的:

<body ui-view="viewA"> 
    <div ng-class="myClass"> 
    <div ui-view="viewC"> 
    <div ui-view="viewB"> 

     <a ui-sref="B"> </a> //Loads the B.html to where viewB is. ControllerB 


     <a ui-sref="C" ng-click="removeClass()"> </a> //Loads the C.html where viewC is. controllerC 


    </div> 

    </div> 

    </div> 

</body> 

按鈕:

<a ng-click="removeClass()"></a> 

缺少什麼我在這裏?我該如何刪除「gnc1」類?

編輯-1:

<div ng-class="{container:dogru, gnc1:yanlis}"> 

indexCtrl:

$scope.dogru = true; 
$scope.yanlis = true; 

按鈕所屬controllerC所以在controllerC:

$scope.removeClass = function($scope) { 
     $scope.dogru = true; 
     $scope.yanlis = false; 
    } 

但這沒有工作無論是。我錯過了什麼?

+2

http://jsfiddle.net/arunpjohny/jae7odee/2/ - 看起來只有精細 –

+0

@Arun P約翰尼拉啊對不起,請單擊EVET觸發一些其他的東西太多,我忘了。點擊該按鈕後,控制器會改變。我要更新我的問題。 – Nasuh

+0

更新並分享小提琴重新創建您的問題 –

回答

1

我建議你使用ng-class這樣反而

<div ng-class="{container:isConditionTruthy, gnc1:!isConditionTruthy}"> 

...ng-click="isConditionTruthy = !isConditionTruthy"... 

如果你發佈你的代碼小提琴我可以告訴你。

+0

它太複雜也創建jsfiddle。你能告訴我一個簡單的例子嗎? – Nasuh

+0

我更新了我的問題。你能看看嗎? – Nasuh

+0

確定https://jsbin.com/hiraguluqu/edit?html,css,js,output –

0

只需將元素彈出即可,因爲要移除的項目位於數組的末尾。

myClass = ["container","gnc1"]; 

removeLast = function() { 
    myClass.pop(); 
} 
removeLast(); 
console.log(myClass);