angularjs - angular access ng-repeat array from child directive -
i had idea angular directive i'm not sure if it's possible.
i have delete , item ng-repeat array, de facto solution have function on scope:
$scope.remove = function(item) { var index = $scope.items.indexof(item); $scope.items.splice(index, 1); }
i'm writing boiler plate code every ng-repeat , nice able instead:
<li ng-repeat="item in items"> <button ng-click-remove="item"></button> </li>
basically i'm thinking directive wrap ng-click, start thinking, possible access items array directive without knowing name or using $parent?
the way create service handling deletion/creation of said task, , use wrapper in controller. mean, way suggesting, still need write same code, in directive. also, yes possible access directive, can pass in controller it.
function dir() { return { controller: 'ctrl ctrl', link: function(scope, elem, attrs, ctrl){ console.log(ctrl.items); console.log(attrs.ngclickremove); // gets value of item. } } }
though caution using ng syntax since should reserved angularjs.
Comments
Post a Comment