国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

angular.js - angularjs how to display div based on dynamic id
給我你的懷抱
給我你的懷抱 2017-05-15 17:08:52
0
7
803

I dynamically set the id code of p in html as follows:


<p ng-repeat="item in items">
    <p id="{{item.name}}" class="ng-hide"> {{item.name}} </p>
<p>

After HTML parsing, the effect of dynamic ID can be seen, similar to this:

<p ng-repeat="item in items">
    <p id="name1" class="ng-hide"> name1 </p>
    <p id="name2" class="ng-hide"> name2 </p>
    <p id="name3" class="ng-hide"> name3 </p>
<p>

I want to dynamically control whether these p's are displayed or not. I wrote this code in js:

html:
<input type="button" ng-click="show(item.name)">
js:
$scope.show=function(name){
    document.getElementById(name).style.display = "block";
}

The result did not achieve the effect I wanted, and three ps were still displayed every time I clicked. Is there any way to achieve the effect I want?

給我你的懷抱
給我你的懷抱

reply all(7)
過去多啦不再A夢

Although I don’t understand why, I changed class="ng-hide" to style="desplay:none" and it worked. . .

劉奇

Is it possible to use ng-show and ng-hide

伊謝爾倫

Add a field "isShow" to item, the default value is false,

<p ng-repeat="item in items">
    <p id="{{item.name}}" class="ng-hide" ng-show="item.isShow"> {{item.name}} </p>
<p>

When the button is clicked, the value of isShow is reversed.

html:
<input type="button" ng-click="show(index)">
js:
$scope.show=function(index){
    $scope.items[index].isShow = !$scope.items[index].isShow;
}
Ty80

There are two ways to control the display of elements in angular.js. The first is: ng-show ng-hide and the other is ng-if

大家講道理

It is recommended to reorganize your data and use ng-hide to control whether elements are hidden or not:

`[
    {
        id:'id1',
        name:'name1',
        hide:false //配合nd-hide實現(xiàn)元素隱藏和顯示
    },
    {
        id:'id2'
        name:'name2',
        hide:true
    }
    //...
]

----------


<p ng-repeat="item in items">
    <p id="item.id" ng-hide="item.hide" ng-bind="item.name"></p>
<p>`
寫的比較簡單,有問題再問
過去多啦不再A夢

Add another attribute, write it to the custom attribute of p, and then ng-if makes the judgment?

阿神

https://github.com/xufei/ng-c...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template