0

I have angular JS with 5 controllers and I want to all of the children inherit all functions of parent (datetimepicker, autorefresh etc.. that is predefined in parent controller) I tried with rootscope but didn't get solution

1 Answer 1

3

you can take common functionality into service/factory an use it in controllers

var app = angular.module('angular', []);

    app.factory("common",function(){
     return {};
    })

   app.controller('ChildCtrl', function($scope, $controller,common) {

    });

or you can inherit from a controller like this

var app = angular.module('angular', []);

    app.controller('ParentCtrl ', function($scope) {
      ctrl to act as parent
    });

    app.controller('ChildCtrl', function($scope, $controller) {
      $controller('ParentCtrl', {$scope: $scope}); 
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.