Calling parent controller method from directives in AngularJS -
Calling parent controller method from directives in AngularJS -
i have situation want phone call parent controller method directive on ng-change. phone call controller method never triggers, not sure wrong. help much appreciated. thanks
sample code:
<body ng-app="content-app" ng-controller="parentcontroller"> <div header-menu report-manager="model"></div> </body>
report-manager model.
header-menu directive:
var $module = angular.module('content-app'); $module.directive('headermenu', function () { homecoming { restrict: 'ae', scope: { reportmanager: '=' }, templateurl: '/scripts/app/directives/header-menu.template.htm' }; });
header-menu.template.htm
<div> <ul> <li ng-repeat="filter in filters" ng-controller="childcontroller" ng-change="method()" /> </ul> </div>
parentcontroller.
angular.module('content-app') .controller("maincontroller", ['$scope', function($scope) { $scope.method = function () { // }; }]);
method needs passed directive "&"
, can pass functions "&"
$module.directive('headermenu', function () { homecoming { restrict: 'ae', scope: { reportmanager: '=', method: "&" // needs passed headermenu directive }, templateurl: '/scripts/app/directives/header-menu.template.htm', link: function(scope, element, attrs){ scope.makechange = function(){ scope.method(); } } }; });
html:
<div header-menu method="method()" report-manager="model"></div>
and
<li ng-repeat="filter in filters" ng-controller="childcontroller" ng-change="makechange()" />
angularjs angularjs-directive angularjs-scope
Comments
Post a Comment