I am new to AngularJS and have some problems understanding the scope concept in Angular. I read some stackoverflow posts, as well as articles on the Internet that advise me to create a custom directive to create an isolation area, but I can't go anywhere ...
As for the project I'm working on, I'm trying to make a button that, when clicked, will launch a text box. However, due to ng-repeat, the text field is triggered for all buttons while I click only one.
My .js file is:
angular.module('myApp') .controller('myCtrl', function ($scope, Question) { scope.visible = false; scope.toggle = function() { scope.visible = !scope.visible; }; .directive("myDirective", function () { return { scope: { ngClick: '&', ngShow: '&' } } });
Here is my HTML file:
<ul> <li ng-repeat="object in objectList"> <button type="text" myDirective ng-click="toggle()">Click</button> <textarea myDirective ng-show="visible"></textarea> </li> </ul>
source share