Is it possible to delete all scope variable of a controller? AngularJS -
I am new to AngularJS and I do not know that it is possible to delete all the scope variables of the controller. I'm the ng-ng-repeater controller, this way.
& lt; Div ng-controller = "main" & gt; & Lt; Div ng-repeat = "ng-controller =" test "in the" x list "& gt; & Lt; Input type = "text" ng-model = "text" & gt; & Lt; Span ng-click = "Remove ($ index)" & gt; X & lt; / Span & gt; & Lt; Div & gt; & Lt; / Div & gt; JS myapp.controller ('main', function ($ scope) {$ scope.list = [1] , 2,3,4]}) myapp.controller ('test', function ($ scope) {$ scope.text = "untitiled"}) I want to remove clicked I'm scared.Someone has helped me or please give me a better suggestion. Thanks
The question is not very clear, but it seems that you want to delete the item after click . Since you are working in the remove index, you can divide it by DOM Auto Update and delete it from the list: $ scope.remove = Function (i) {$ scope.list.splice (i, 1); Console.log ($ scope.list); } In this event you are doing something different in which you want to hide it, you can press index in another array and then ng-show Or ng-hide . $ scope.remove2 = function (i) {$ scope.hideList.push (i); } $ Scope.shouldHide = function (i) {return $ scope.hideList.indexOf (i)! = - 1; } & Lt; Div ng-repeat = "number in number2" & gt; {{Number}} & lt; Span ng-hide = 'shouldhd ($ index)' ng-click = "removed 2 ($ index)" & gt; X & lt; / Span & gt; & Lt; / Div & gt; Here is a simple example of both scenarios: In real life, generally we are working with arrays of objects and what you can do, property on any one of the objects. As a way to set up and control it. DEMO:
If you really want to remove all keys from the scope:
Remove the function () {key ($ scope in the key ) {If (key.substr (0,1)! = '$' And amp; key! = 'This') Delete the $ radius [key]; }}
Comments
Post a Comment