Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am new to Angular.js and I am trying to make a custom directive(which has a controller with functions in it) that is linked to a controller. When an object in the controller($scope.MyObj), changes I would like to have a similar object in my directive controller that changes the same way. In addition is it possible to invoke a function/scope method that is declared in my directive controller, from my basic controller(or invoke a function from my directive controller when an object from the basic controller has changed.) ?

share|improve this question

Aviv Ben-Yosef writes a pretty nice post about it on http://www.codelord.net where he basically hooks into the controller from a isolated directive scope:

http://www.codelord.net/2015/09/02/controller-directive-communication-part-3-controller-to-directive/

share|improve this answer

if you are using Angular 1.4 and above you can use bindToController something like this:

.directive('mdAddress', function mdAddress() {
    var directive = {
      restrict: 'EA',
      scope: {},
      bindToController: {
        address: '='
      },
      templateUrl: 'modules/address/address.html',
      controller: AddressController,
      controllerAs: 'dir'
    };
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.