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

I'm working on an angular app using the NG6-Starter boilerplate.

Now, i've got one component with another component inside it, and i'm sending a callback function to the inner component via an attribute. This is how i'm initializing the inner component:

<div>
<location-form location='vm.location' submit-callback='vm.addLocation'>
</location-form>
</div>

The addLocation function on the parent controller gets called, but the problem is it's being called with this being the controller of the child component (location-form).

I tried using bind, but angular has issues with that.. Any ideas?

Component definition:

import template from './locationForm.html';
import controller from './locationForm.controller';
import './locationForm.styl';

let locationFormComponent = {
  restrict: 'E',
  bindings: {
    location: '=',
    submitCallback: '=',
    parentController: '='
  },
  template,
  controller,
  controllerAs: 'vm'
};

export default locationFormComponent;

Controller:

<form ng-submit="vm.submitCallback(vm.location)">
     ...
      <button type="submit" class="btn btn-default">Submit</button>
</form>

Thanks, Uri

share|improve this question
1  
Can you post your directive code? – o4ohel 18 hours ago
    
Added. Right now i'm solving it by passing the parent controller as a prop – Uri Klar 17 hours ago
    
if you want your directive to have the same parent controller/scope (vm) as it's parent, you can define scope: false – svarog 10 hours ago
    
And controller code is?.. – estus 7 hours ago
    
the controller isn't really relevant since the function being called is called from the view and it's the callback function – Uri Klar 2 hours ago

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.