I try to run the ES6 constructor code when the 'soran' tag is loaded. but it just ignores. how can I run certain code by using a controller in angular 1.5 component() ?
import { config } from './index.config';
import { routerConfig } from './index.route';
import { runBlock } from './index.run';
import { MainController } from './main/main.controller';
angular.module('soranSpace', ['ngAnimate', 'ngCookies', 'ngSanitize', 'ngMessages', 'ngAria', 'restangular', 'ui.router'])
.config(config)
.config(routerConfig)
.run(runBlock)
.controller('MainController', MainController)
.component('soran', {
bindings: {},
template: '<div id="map-viewport"></div>',
scope: {},
controller: soranController
});
class soranController {
constructor($log) {
'ngInject';
$log.log("run!"); // how to run this ?
}
}
Move the class definition above the component definition. In ES6, class declarations are not hoisted, so soranController is not defined at the time where your component is defined. I ran into this same issue last week, and it didn't throw any error for some reason - I reckon it's something to do with how the code gets transpiled.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Hoisting
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With