How Do I Inject This Directive into My Angularjs Controller?

How Do I Inject This Directive into My Angularjs Controller?

I want to use the code form this Plunk.

It has a directive:

myApp.directive('fileModel', ['$parse', function ($parse) {

and a service

myApp.service('fileUpload', ['$http', function ($http) {

and the example injects into the controller thusly:

myApp.controller('myCtrl', ['$scope', 'fileUpload', function($scope, fileUpload){

I have this:

angular
    .module('Dashboard')
    .controller('DashboardController', DashboardController);

and

function DashboardController($rootScope, $scope, $http, 
                             $interval, $state, $location)
{

But I can't figure out how to inject the file upload into my controller :-(

8

1 Answer

Try like this. i think your problem is for module name.i define fileUpload service in same module for DashboardController

  var myApp = angular.module("yourAppName",[]);
  myApp.directive('fileModel', ['$parse', function ($parse) {
  ...

  myApp.service('fileUpload', ['$http', function ($http) {
  ...

 myApp.controller('DashboardController', DashboardController);


function DashboardController($rootScope, $scope, $http, 
                         $interval, $state, $location,fileUpload)
   {
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.