<div id="whole-div" ng-hide="hideme"> <div id="loop-div" ng-repeat="i in [1, 2, 3]"> <button ng-click="hideme=true">button {{i}}</button> </div> </div> above code have right now. want when click 1 of buttons made within loop (button1, button2, button3), whole div hidden. however, found can hide whole div when button on outside follows...
<div id="whole-div" ng-hide="hideme"> <div id="loop-div" ng-repeat="i in [1, 2, 3]"> <button>button {{i}}</button> </div> <button ng-click="hideme=true">final button</button> </div> is there way hide whole div using 1 of inner buttons in loop div? in advance!
ng-repeat creates local scope variable hideme belongs local scope. there in fact 3 variables hideme, each in scope of button.
setting property on $parent scope should work , let hideme variable unique whole div:
var app = angular.module('app', []); app.controller('mainctrl', function($scope) { }); <!doctype html> <html ng-app="app"> <head> <meta charset="utf-8" /> <script src="https://code.angularjs.org/1.2.28/angular.js"></script> </head> <body ng-controller="mainctrl"> <!-- here scope of mainctrl, hideme can used --> <button ng-click="hideme=false">show all</button> <div id="whole-div" ng-hide="hideme"> <div id="loop-div" ng-repeat="i in [1, 2, 3]"> <!-- here scope of button, hideme have prefix $parent access right property --> <button ng-click="$parent.hideme=true">button {{i}}</button> </div> </div> </body> </html>
Comments
Post a Comment