0

Is it possible to get around AngularJS's dependency injection and use ECMAScript 2015+ modules instead?

My goal is to never have to call angular.module on controllers, services, and factories. I can do that for those easily, but if I want to access $http and other similar providers, I only know how to get to them via dependency injection. Is there a way to pull them in with an import statement or from the angular instance?

0

1 Answer 1

0

Controller is just a function, factory is just a function, Component is just an object.

controller.js:

export default ['$scope', function($scope) {...}]

component.js:

export default {...}

module.js:

import com from 'component.js'
import contr from 'controller.js'
angular.module('module', []).component('c1', com).controller('contr1', contr);
export default angular.module('module').name
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.