2017-02-06 3 views
0

Ich versuche ng-file-upload in meinem einfachen Winkel js Projekt zu verwenden, aber wenn ich versuche, npm install zu tun, erhalte ich die Fehler unter

js/controllers/HomePageController.js: Zeile 18, Spalte 11, Erwartet '{' und stattdessen sah '$ Scope'. js/controllers/HomePageController.js: Zeile 23, Spalte 4, fehlendes Semikolon.

Mein JS Ordner ist wie unter

. 
├── app_module.js 
├── controllers 
│   └── HomePageController.js 
└── directives 
    ├── GreetBox.js 
    └── HomePageGreetingBox.js 

und ich in den folgenden Code haben HomePageController.js

angular.module('app').controller('HomePageController', ['$scope', 'Upload', '$timeout', function ($scope, Upload, $timeout) { 
    'use strict'; 

    $scope.greetingText = 'Get to somehrere!'; 

    $scope.uploadPic = function(file) { 
     file.upload = Upload.upload({ 
      url: 'https://angular-file-upload-cors-srv.appspot.com/upload', 
      data: {username: $scope.username, file: file}, 
     }); 

     file.upload.then(function (response) { 
      $timeout(function() { 
      file.result = response.data; 
      }); 
     }, function (response) { 
      if (response.status > 0) 
      $scope.errorMsg = response.status + ': ' + response.data; 
     }, function (evt) { 
      // Math.min is to fix IE which reports 200% sometimes 
      file.progress = Math.min(100, parseInt(100.0 * evt.loaded/evt.total)); 
     }); 
    } 

}]); 

und der Code in app_module.js unter

;(function (angular) { 
    'use strict'; 
    angular.module('app', []); 
})(angular); 

Verwendung String gibt den folgenden Fehler

➜ angular-skeleton git:(master) ✗ npm install && node server.js 

> [email protected] postinstall /Users/anthony/code/angular/angular-skeleton 
> bower install && node_modules/.bin/gulp 

bower angular   extra-resolution Unnecessary resolution: angular#~1.5.0 
[12:37:40] Using gulpfile ~/code/angular/angular-skeleton/gulpfile.js 
[12:37:40] Starting 'clean'... 
[12:37:40] Finished 'clean' after 4.22 ms 
[12:37:40] Starting 'lint'... 
[12:37:40] Starting 'views'... 
[12:37:40] Starting 'app'... 
[12:37:40] Starting 'vendor'... 
[12:37:40] Starting 'css'... 
[12:37:40] Finished 'css' after 6.84 ms 
js/controllers/HomePageController.js: line 2, col 5, Missing "use strict" statement. 
js/controllers/HomePageController.js: line 16, col 13, Expected '{' and instead saw '$scope'. 
js/controllers/HomePageController.js: line 21, col 6, Missing semicolon. 

Antwort

1

entfernen die 'use strict' entfernen;

angular.module('app').controller('HomePageController', ['$scope', 'Upload', '$timeout', function ($scope, Upload, $timeout) { 
    $scope.greetingText = 'Get to somehrere!'; 

    $scope.uploadPic = function(file) { 
     file.upload = Upload.upload({ 
      url: 'https://angular-file-upload-cors-srv.appspot.com/upload', 
      data: {username: $scope.username, file: file}, 
     }); 

     file.upload.then(function (response) { 
      $timeout(function() { 
      file.result = response.data; 
      }); 
     }, function (response) { 
      if (response.status > 0) 
      $scope.errorMsg = response.status + ': ' + response.data; 
     }, function (evt) { 
      // Math.min is to fix IE which reports 200% sometimes 
      file.progress = Math.min(100, parseInt(100.0 * evt.loaded/evt.total)); 
     }); 
    } 

}]); 
+0

Jetzt bekomme ich einen Fehler 'Missing "use strict" statement.' – Anthony

+0

sollte es außerhalb – Sajeetharan

+0

leid kommen, nach draußen, wo? Ich bin neu in AngularJS – Anthony

Verwandte Themen