javascript - Controller function after ngChange event in directive -
i found questions , examples, utilize $scope, far not using $scope in application. trying execute controller function when checkbox in directive gets selected (ng-change).
jsfiddle
html
<div ng-app="myapp" ng-controller="controller ctrl"> <dir-select doit="ctrl.doit()" object="ctrl.object"> </div>
controller , directive
var app = angular.module('myapp', []); app.controller("controller",[ function() { var ctrl = this; ctrl.object = { name: "test", selected: false }; ctrl.doit = function() { alert("doing it!"); }; }]); app.directive('dirselect', function() { homecoming { restrict: 'e', template: '<input type="checkbox" ng-model="object.selected" ng-change="doit()">select', scope: { object: '=', doit: '&' } } });
what missing?
please seek this
<dir-select do-it="ctrl.doit()" object="ctrl.object">
and in directive
template: '<input type="checkbox" ng-model="object" ng-change="doit()">select',
javascript angularjs
No comments:
Post a Comment