angularjs - Call Angular directive controller method from another controller -
i have directive associated 1 controller , functions in controller defined
myformcontroller.prototype.addnewrow = function addnewrow() { //adding row code };
i want call method controller, possible ways?
i ve user service , moved code service shared across controllers, service code dom manipulation, , guess next question can use $compile in service test case
service or factory used share data between controller.so best define function in service , factory.
demo:
(function() { angular.module('app', []) .service('svc', function() { var svc = {}; svc.method = function() { alert(1); } return svc; }) .controller('ctrl', [ '$scope', 'svc', function($scope, svc) { svc.method(); } ]); })();
Comments
Post a Comment