Mawg
Mawg

Reputation: 40140

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 :-(

Upvotes: 1

Views: 4721

Answers (1)

Hadi
Hadi

Reputation: 17289

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)
   {

Upvotes: 1

Related Questions