2016-07-21 9 views
0

Ich versuche, $ http in meine eckigen Service zu injizieren, die von meinem Controller aufgerufen wird, um Daten aus unserer API zu füllen. Ich fahre fort, diesen Fehler zu treffen:

Fehler: [$ Injektor: strictdi]? Info nicht explizit Annotation verwendet und kann nicht im strikten Modus http://errors.angularjs.org/1.5.7/ $ Injektor/strictdi p0 = Info

unter der Service aufgerufen werden was als streng definiert ist. Wie kann ich $ http richtig injizieren?

Der Dienst muss streng bleiben.

'use strict'; 
 

 
angular.module('bitsGantt') 
 
    .service('Infoservice', function Infoservice($http) { 
 
     return { 
 
      getSampleData: function() { 
 
      \t // $http({ 
 
      \t // \t method: 'GET', 
 
      \t // \t URL: 
 
      \t // }) 
 
       return [ 
 
         // Order is optional. If not specified it will be assigned automatically 
 
         {name: 'Milestones', height: '3em', sortable: false, drawTask: false, classes: 'gantt-row-milestone', color: '#45607D', tasks: [ 
 
          // Dates can be specified as string, timestamp or javascript date object. The data attribute can be used to attach a custom object 
 
          {name: 'Kickoff', color: '#93C47D', from: '2016-10-07T09:00:00', to: '2016-10-07T10:00:00', data: 'Can contain any custom data or object'}, 
 
          {name: 'Concept approval', color: '#93C47D', from: new Date(2016, 9, 18, 18, 0, 0), to: new Date(2016, 9, 18, 18, 0, 0), est: new Date(2016, 9, 16, 7, 0, 0), lct: new Date(2016, 9, 19, 0, 0, 0)}, 
 
          {name: 'Development finished', color: '#93C47D', from: new Date(2016, 10, 15, 18, 0, 0), to: new Date(2016, 10, 15, 18, 0, 0)}, 
 
          {name: 'Shop is running', color: '#93C47D', from: new Date(2016, 10, 22, 12, 0, 0), to: new Date(2016, 10, 22, 12, 0, 0)}, 
 
          {name: 'Go-live', color: '#93C47D', from: new Date(2016, 10, 29, 16, 0, 0), to: new Date(2016, 10, 29, 16, 0, 0)} 
 
         ], data: 'This here can contain any custom data, or even an object!'}, 
 
         {name: 'Status meetings', tasks: [ 
 
          {name: 'Bits Demo #1', color: '#9FC5F8', from: new Date(2016, 9, 25, 15, 0, 0), to: new Date(2016, 9, 25, 18, 30, 0)}, 
 
          {name: 'Bits Demo #2', color: '#9FC5F8', from: new Date(2016, 10, 1, 15, 0, 0), to: new Date(2016, 10, 1, 18, 0, 0)}, 
 
          {name: 'Bits Demo #3', color: '#9FC5F8', from: new Date(2016, 10, 8, 15, 0, 0), to: new Date(2016, 10, 8, 18, 0, 0)}, 
 
          {name: 'Bits Demo #4', color: '#9FC5F8', from: new Date(2016, 10, 15, 15, 0, 0), to: new Date(2016, 10, 15, 18, 0, 0)}, 
 
          {name: 'Bits Demo #5', color: '#9FC5F8', from: new Date(2016, 10, 24, 9, 0, 0), to: new Date(2016, 10, 24, 10, 0, 0)} 
 
         ]}, 
 
         {name: 'Kickoff', movable: {allowResizing: false}, tasks: [ 
 
          {name: 'Day 1', color: '#9FC5F8', from: new Date(2016, 9, 7, 9, 0, 0), to: new Date(2016, 9, 7, 17, 0, 0), 
 
           progress: {percent: 100, color: '#3C8CF8'}, movable: false}, 
 
          {name: 'Day 2', color: '#9FC5F8', from: new Date(2016, 9, 8, 9, 0, 0), to: new Date(2016, 9, 8, 17, 0, 0), 
 
           progress: {percent: 100, color: '#3C8CF8'}}, 
 
          {name: 'Day 3', color: '#9FC5F8', from: new Date(2016, 9, 9, 8, 30, 0), to: new Date(2016, 9, 9, 12, 0, 0), 
 
           progress: {percent: 100, color: '#3C8CF8'}} 
 
         ]}, 
 
         {name: 'Create concept', tasks: [ 
 
          {name: 'Create concept', priority: 20, content: '<i class="fa fa-cog" ng-click="scope.handleTaskIconClick(task.model)"></i> {{task.model.name}}', color: '#F1C232', from: new Date(2016, 9, 10, 8, 0, 0), to: new Date(2016, 9, 16, 18, 0, 0), est: new Date(2016, 9, 8, 8, 0, 0), lct: new Date(2016, 9, 18, 20, 0, 0), 
 
           progress: 100} 
 
         ]}, 
 
         {name: 'Finalize concept', tasks: [ 
 
          {id: 'Finalize concept', name: 'Finalize concept', priority: 10, color: '#F1C232', from: new Date(2016, 9, 17, 8, 0, 0), to: new Date(2016, 9, 18, 18, 0, 0), 
 
           progress: 100} 
 
         ]}, 
 
         {name: 'Development', children: ['Sprint 1', 'Sprint 2', 'Sprint 3', 'Sprint 4'], content: '<i class="fa fa-file-code-o" ng-click="scope.handleRowIconClick(row.model)"></i> {{row.model.name}}'}, 
 
         {name: 'Sprint 1', tooltips: false, tasks: [ 
 
          {id: 'Product list view', name: 'Product list view', color: '#F1C232', from: new Date(2016, 9, 21, 8, 0, 0), to: new Date(2016, 9, 25, 15, 0, 0), 
 
           progress: 25, dependencies: [{to: 'Order basket'}, {from: 'Finalize concept'}]} 
 
         ]}, 
 
         {name: 'Sprint 2', tasks: [ 
 
          {id: 'Order basket', name: 'Order basket', color: '#F1C232', from: new Date(2016, 9, 28, 8, 0, 0), to: new Date(2016, 10, 1, 15, 0, 0), 
 
           dependencies: {to: 'Checkout'}} 
 
         ]}, 
 
         {name: 'Sprint 3', tasks: [ 
 
          {id: 'Checkout', name: 'Checkout', color: '#F1C232', from: new Date(2016, 10, 4, 8, 0, 0), to: new Date(2016, 10, 8, 15, 0, 0), 
 
           dependencies: {to: 'Login & Signup & Admin Views'}} 
 
         ]}, 
 
         {name: 'Sprint 4', tasks: [ 
 
          {id: 'Login & Signup & Admin Views', name: 'Login & Signup & Admin Views', color: '#F1C232', from: new Date(2016, 10, 11, 8, 0, 0), to: new Date(2016, 10, 15, 15, 0, 0), 
 
           dependencies: [{to: 'HW'}, {to: 'SW/DNS/ Backups'}]} 
 
         ]}, 
 
         {name: 'Hosting'}, 
 
         {name: 'Setup', tasks: [ 
 
          {id: 'HW', name: 'HW', color: '#F1C232', from: new Date(2016, 10, 18, 8, 0, 0), to: new Date(2016, 10, 18, 12, 0, 0)} 
 
         ]}, 
 
         {name: 'Config', tasks: [ 
 
          {id: 'SW/DNS/ Backups', name: 'SW/DNS/ Backups', color: '#F1C232', from: new Date(2016, 10, 18, 12, 0, 0), to: new Date(2016, 10, 21, 18, 0, 0)} 
 
         ]}, 
 
         {name: 'Server', parent: 'Hosting', children: ['Setup', 'Config']}, 
 
         {name: 'Deployment', parent: 'Hosting', tasks: [ 
 
          {name: 'Depl. & Final testing', color: '#F1C232', from: new Date(2016, 10, 21, 8, 0, 0), to: new Date(2016, 10, 22, 12, 0, 0), 'classes': 'gantt-task-deployment'} 
 
         ]}, 
 
         {name: 'Workshop', tasks: [ 
 
          {name: 'On-side education', color: '#F1C232', from: new Date(2016, 10, 24, 9, 0, 0), to: new Date(2016, 10, 25, 15, 0, 0)} 
 
         ]}, 
 
         {name: 'Content', tasks: [ 
 
          {name: 'Supervise content creation', color: '#F1C232', from: new Date(2016, 10, 26, 9, 0, 0), to: new Date(2016, 10, 29, 16, 0, 0)} 
 
         ]}, 
 
         {name: 'Documentation', tasks: [ 
 
          {name: 'Technical/User documentation', color: '#F1C232', from: new Date(2016, 10, 26, 8, 0, 0), to: new Date(2016, 10, 28, 18, 0, 0)} 
 
         ]} 
 
        //close of return 
 
        ]; 
 
      //close of function   
 
      }, 
 
      getSampleTimespans: function() { 
 
       return [ 
 
         { 
 
          from: new Date(2016, 9, 21, 8, 0, 0), 
 
          to: new Date(2016, 9, 25, 15, 0, 0), 
 
          name: 'Sprint 1 Timespan' 
 
          //priority: undefined, 
 
          //classes: [], 
 
          //data: undefined 
 
         } 
 
        //close of return  
 
        ]; 
 
      //close of function   
 
      } 
 
     //close of main return  
 
     }; 
 
    //close of info service  
 
    }) 
 
;

Antwort

0

Versuchen Sie, Ihre Funktion innerhalb eines Arrays Einwickeln und $ http als das erste Element des Arrays deklarieren, so sieht es wie folgt aus:

'use strict'; 

angular.module('bitsGantt') 
    .service('Infoservice', ['$http', function Infoservice($http) { 
     return { 
      getSampleData: function() { 
       // $http({ 
       // method: 'GET', 
       // URL: 
       // }) 
       return [ 
         // Order is optional. If not specified it will be assigned automatically 
         {name: 'Milestones', height: '3em', sortable: false, drawTask: false, classes: 'gantt-row-milestone', color: '#45607D', tasks: [ 
          // Dates can be specified as string, timestamp or javascript date object. The data attribute can be used to attach a custom object 
          {name: 'Kickoff', color: '#93C47D', from: '2016-10-07T09:00:00', to: '2016-10-07T10:00:00', data: 'Can contain any custom data or object'}, 
          {name: 'Concept approval', color: '#93C47D', from: new Date(2016, 9, 18, 18, 0, 0), to: new Date(2016, 9, 18, 18, 0, 0), est: new Date(2016, 9, 16, 7, 0, 0), lct: new Date(2016, 9, 19, 0, 0, 0)}, 
          {name: 'Development finished', color: '#93C47D', from: new Date(2016, 10, 15, 18, 0, 0), to: new Date(2016, 10, 15, 18, 0, 0)}, 
          {name: 'Shop is running', color: '#93C47D', from: new Date(2016, 10, 22, 12, 0, 0), to: new Date(2016, 10, 22, 12, 0, 0)}, 
          {name: 'Go-live', color: '#93C47D', from: new Date(2016, 10, 29, 16, 0, 0), to: new Date(2016, 10, 29, 16, 0, 0)} 
         ], data: 'This here can contain any custom data, or even an object!'}, 
         {name: 'Status meetings', tasks: [ 
          {name: 'Bits Demo #1', color: '#9FC5F8', from: new Date(2016, 9, 25, 15, 0, 0), to: new Date(2016, 9, 25, 18, 30, 0)}, 
          {name: 'Bits Demo #2', color: '#9FC5F8', from: new Date(2016, 10, 1, 15, 0, 0), to: new Date(2016, 10, 1, 18, 0, 0)}, 
          {name: 'Bits Demo #3', color: '#9FC5F8', from: new Date(2016, 10, 8, 15, 0, 0), to: new Date(2016, 10, 8, 18, 0, 0)}, 
          {name: 'Bits Demo #4', color: '#9FC5F8', from: new Date(2016, 10, 15, 15, 0, 0), to: new Date(2016, 10, 15, 18, 0, 0)}, 
          {name: 'Bits Demo #5', color: '#9FC5F8', from: new Date(2016, 10, 24, 9, 0, 0), to: new Date(2016, 10, 24, 10, 0, 0)} 
         ]}, 
         {name: 'Kickoff', movable: {allowResizing: false}, tasks: [ 
          {name: 'Day 1', color: '#9FC5F8', from: new Date(2016, 9, 7, 9, 0, 0), to: new Date(2016, 9, 7, 17, 0, 0), 
           progress: {percent: 100, color: '#3C8CF8'}, movable: false}, 
          {name: 'Day 2', color: '#9FC5F8', from: new Date(2016, 9, 8, 9, 0, 0), to: new Date(2016, 9, 8, 17, 0, 0), 
           progress: {percent: 100, color: '#3C8CF8'}}, 
          {name: 'Day 3', color: '#9FC5F8', from: new Date(2016, 9, 9, 8, 30, 0), to: new Date(2016, 9, 9, 12, 0, 0), 
           progress: {percent: 100, color: '#3C8CF8'}} 
         ]}, 
         {name: 'Create concept', tasks: [ 
          {name: 'Create concept', priority: 20, content: '<i class="fa fa-cog" ng-click="scope.handleTaskIconClick(task.model)"></i> {{task.model.name}}', color: '#F1C232', from: new Date(2016, 9, 10, 8, 0, 0), to: new Date(2016, 9, 16, 18, 0, 0), est: new Date(2016, 9, 8, 8, 0, 0), lct: new Date(2016, 9, 18, 20, 0, 0), 
           progress: 100} 
         ]}, 
         {name: 'Finalize concept', tasks: [ 
          {id: 'Finalize concept', name: 'Finalize concept', priority: 10, color: '#F1C232', from: new Date(2016, 9, 17, 8, 0, 0), to: new Date(2016, 9, 18, 18, 0, 0), 
           progress: 100} 
         ]}, 
         {name: 'Development', children: ['Sprint 1', 'Sprint 2', 'Sprint 3', 'Sprint 4'], content: '<i class="fa fa-file-code-o" ng-click="scope.handleRowIconClick(row.model)"></i> {{row.model.name}}'}, 
         {name: 'Sprint 1', tooltips: false, tasks: [ 
          {id: 'Product list view', name: 'Product list view', color: '#F1C232', from: new Date(2016, 9, 21, 8, 0, 0), to: new Date(2016, 9, 25, 15, 0, 0), 
           progress: 25, dependencies: [{to: 'Order basket'}, {from: 'Finalize concept'}]} 
         ]}, 
         {name: 'Sprint 2', tasks: [ 
          {id: 'Order basket', name: 'Order basket', color: '#F1C232', from: new Date(2016, 9, 28, 8, 0, 0), to: new Date(2016, 10, 1, 15, 0, 0), 
           dependencies: {to: 'Checkout'}} 
         ]}, 
         {name: 'Sprint 3', tasks: [ 
          {id: 'Checkout', name: 'Checkout', color: '#F1C232', from: new Date(2016, 10, 4, 8, 0, 0), to: new Date(2016, 10, 8, 15, 0, 0), 
           dependencies: {to: 'Login & Signup & Admin Views'}} 
         ]}, 
         {name: 'Sprint 4', tasks: [ 
          {id: 'Login & Signup & Admin Views', name: 'Login & Signup & Admin Views', color: '#F1C232', from: new Date(2016, 10, 11, 8, 0, 0), to: new Date(2016, 10, 15, 15, 0, 0), 
           dependencies: [{to: 'HW'}, {to: 'SW/DNS/ Backups'}]} 
         ]}, 
         {name: 'Hosting'}, 
         {name: 'Setup', tasks: [ 
          {id: 'HW', name: 'HW', color: '#F1C232', from: new Date(2016, 10, 18, 8, 0, 0), to: new Date(2016, 10, 18, 12, 0, 0)} 
         ]}, 
         {name: 'Config', tasks: [ 
          {id: 'SW/DNS/ Backups', name: 'SW/DNS/ Backups', color: '#F1C232', from: new Date(2016, 10, 18, 12, 0, 0), to: new Date(2016, 10, 21, 18, 0, 0)} 
         ]}, 
         {name: 'Server', parent: 'Hosting', children: ['Setup', 'Config']}, 
         {name: 'Deployment', parent: 'Hosting', tasks: [ 
          {name: 'Depl. & Final testing', color: '#F1C232', from: new Date(2016, 10, 21, 8, 0, 0), to: new Date(2016, 10, 22, 12, 0, 0), 'classes': 'gantt-task-deployment'} 
         ]}, 
         {name: 'Workshop', tasks: [ 
          {name: 'On-side education', color: '#F1C232', from: new Date(2016, 10, 24, 9, 0, 0), to: new Date(2016, 10, 25, 15, 0, 0)} 
         ]}, 
         {name: 'Content', tasks: [ 
          {name: 'Supervise content creation', color: '#F1C232', from: new Date(2016, 10, 26, 9, 0, 0), to: new Date(2016, 10, 29, 16, 0, 0)} 
         ]}, 
         {name: 'Documentation', tasks: [ 
          {name: 'Technical/User documentation', color: '#F1C232', from: new Date(2016, 10, 26, 8, 0, 0), to: new Date(2016, 10, 28, 18, 0, 0)} 
         ]} 
        //close of return 
        ]; 
      //close of function   
      }, 
      getSampleTimespans: function() { 
       return [ 
         { 
          from: new Date(2016, 9, 21, 8, 0, 0), 
          to: new Date(2016, 9, 25, 15, 0, 0), 
          name: 'Sprint 1 Timespan' 
          //priority: undefined, 
          //classes: [], 
          //data: undefined 
         } 
        //close of return  
        ]; 
      //close of function   
      }] 
     //close of main return  
     }; 
    //close of info service  
    }) 
; 
+0

gearbeitet! Danke. eckig ist verwirrend. – troz

+0

Sicher Sache! Bitte markieren Sie die Frage als beantwortet, wenn Sie Zeit haben :) – nixkuroi

+1

Ich habe das Häkchen neben Ihrer Antwort angeklickt! Danke nochmal! – troz

Verwandte Themen