We can use functionality of one controller into another controller
Here for injecting one controller into another one we have to use $controller service
it will instantiate a controller inside another controller
Syntax:
app.controller('Cntrl1', function () {
this.MethodTest = function () {
// functionality
}
});
app.controller('Cntrl2', ['$scope', '$controller', function ($scope, $controller) {
var testCtrl= $controller('Cntrl1');
testCtrll.MethodTest();
}]);
Here for injecting one controller into another one we have to use $controller service
it will instantiate a controller inside another controller
Syntax:
app.controller('Cntrl1', function () {
this.MethodTest = function () {
// functionality
}
});
app.controller('Cntrl2', ['$scope', '$controller', function ($scope, $controller) {
var testCtrl= $controller('Cntrl1');
testCtrll.MethodTest();
}]);
Comments
Post a Comment