Search code examples
javascriptangularjsangularjs-components

How To Inject Service Into Angular 1.5 Component (No Typescript)


I have a service that I want to pass into a Component in Angular 1.5. I'm not using Gulp or TypeScript.

This is the service:

(function() {'use strict';
angular.module('flavorApplication')
  .component('app', {
  	templateUrl: "app/app.component.html",
    controllerAs: "vm",
  	controller: function AppController() {

This is the Component:

(function() {'use strict';
angular.module('flavorApplication')
  .component('app', {
  	templateUrl: "app/app.component.html",
    controllerAs: "vm",
  	controller: function AppController('DataService')

This didn't work. I also tried:

controller: ['DataService', function AppController('DataService')

This also didn't work. Keep in mind I'm new to angular and just getting my feed under me. Thank you for your help!


Solution

  • You don't need the single quotes.

    controller: function AppController(DataService)