0

Having this controller:

class FirstController{
    constructor(){
        ...
    }

    $onInit(){
    }

    updateField(name) {
    ...
        this.callback({id: name});
    }
}

const firstController={
    bindings: {
        site: '<',
        callback: '&'
    },
    controller:FirstController,
    templateUrl:require('./FirstController.html')
};

export default firstController;

I want to call the callback() method into another one, so I did it like this:

import firstController from './../core/firstController/firstController.js';

class SecondCtrl {
    constructor(SecondService, ...) {

    reset() {
        firstController.callback();

         ...

    }
   }

It doesn't work, I get this error message:

Uncaught ReferenceError: firstController is not defined

Any suggestions?

AT82
  • 71,416
  • 24
  • 140
  • 167
dadsa
  • 177
  • 1
  • 13
  • 1
    `angularjs` tag is for angular 1.x, this code looks more angular 2+ (tag is `angular`) to me, can you confirm the version? – Kaddath Mar 16 '18 at 14:04
  • you are missing curly braces in your import **{ firstController } **. – Immanuel Kirubaharan Mar 16 '18 at 14:05
  • If the common functionality can be part of some service, better put it there and inject the service in both controllers. If not take a look at this one https://stackoverflow.com/questions/25417162/how-do-i-inject-a-controller-into-another-controller-in-angularjs – GSSwain Mar 16 '18 at 14:39
  • @Kaddath This is AngularJS, "modernized" :) – AT82 Mar 16 '18 at 19:34
  • Possible duplicate of [Can one controller call another?](https://stackoverflow.com/questions/9293423/can-one-controller-call-another) – Heretic Monkey Mar 16 '18 at 19:50

0 Answers0