2013-12-11 12 views
0

我是新來的angularjs。我使用ng-repeat創建了列表。只是我想隱藏從列表中選擇的列表元素:我想只隱藏特定列表元素

的HTML代碼,我者優先:

<ul> 
<li ng-repeat="profile in profileMenu"> 
    <div class="hederMenu" ng-hide="configureDisplay" ng-click="setProfile(profile.name)"> 
    <a class="anchor" style="width:100%" >{{profile.name}}</a> 
    </div> 
</li> 
</ul> 

這裏是控制器代碼

$scope.profileMenu = [{ 
     name : "My Profile" 
    }, { 
     name : "Configure" 
    }, { 
     name : "Logout" 
    } 
]; 

$scope.profile = ""; 
$scope.setProfile = function (test) { 
    $scope.profileSelected = test; 
    if ($scope.profileSelected == "Configure") { 
     $location.path("/home/configure"); // if user click configure then this element will hide 
     $scope.configureDisplay = true; 
    } 
    if ($scope.profileSelected == "My Profile") { 
     $location.path("/home/dashboard"); 
     $scope.configureDisplay = false; 
    } 
    if ($scope.profileSelected == "Logout") { 
     window.location.assign("http://mitesh.demoilab.pune/") 
    } 
    return $scope.profileSelected = test; 
} 
+0

什麼是您所遇到的問題? –

+0

點擊列表元素所有列表元素現在隱藏 –

+0

只是我想隱藏特定列表元素隱藏 –

回答

2

必須設置在實際的「配置」配置文件項configureDisplay財產。不知道你在選擇列表中做了什麼,但我想在選擇另一個項目時,你會希望「配置」項目再次可見。因此,在選擇另一個項目時,您還必須將「配置」項目重置爲false。

我修改了你的例子。注意,不是在setProfile上傳遞profile.name,而是傳遞profile對象。這只是簡化了交互。

<ul> 
<li ng-repeat="profile in profileMenu"> 
    <div class="hederMenu" ng-hide="profile.configureDisplay" ng-click="setProfile(profile)"> 
    <a class="anchor" style="width:100%" >{{profile.name}}</a> 
    </div> 
</li> 
</ul> 

$scope.setProfile = function (selectedProfile) {  
    //reset the items 
    for (var i in $scope.profileMenu) { 
     $scope.profileMenu[i].configureDisplay = false; 
    } 

    if (selectedProfile.name == "Configure") { 
     $location.path("/home/configure"); // if user click configure then this element will hide 
     selectedProfile.configureDisplay = true; 
    } 
    if (selectedProfile.name == "My Profile") { 
     $location.path("/home/dashboard"); 
    } 
    if (selectedProfile.name == "Logout") { 
     window.location.assign("http://mitesh.demoilab.pune/") 
    } 
    return true; 
} 
+1

Y你對,我只是想重置回配置。這就是我想要的答案......謝謝.. @ reinard –

0

你需要做一些改變,

<li ng-repeat="profile in profileMenu"> 
    <div class="hederMenu" ng-hide="profile.configureDisplay" ng-click="setProfile(profile)"> 
    <a class="anchor" style="width:100%" >{{profile.name}}</a> 
    </div> 
</li> 

而在控制器中,

$scope.setProfile = function (test) { 
    $scope.profileSelected = test.name; 
    if ($scope.profileSelected == "Configure") { 
     $location.path("/home/configure"); 
     test.configureDisplay = true; 

    } 
    if ($scope.profileSelected == "My Profile") { 
     $location.path("/home/dashboard"); 
     test.configureDisplay = false; 

    } 
    if ($scope.profileSelected == "Logout") { 
     window.location.assign("http://mitesh.demoilab.pune/") 
    } 
    return test; 
} 
+0

沒有jayantha這不是我所需要的。 –