1

I'm using plunker and I have a separate angular file app.js. I want to 'use strict' but I get 'angular' is not defined. Is there a way to avoid this error and keep app.js as a separate file? Here is my code app.js code

   'use strict';

   var app = angular.module('plunker', []);

   app.controller('MainCtrl', function($scope) {
     $scope.name = 'World';
   });
4

1 回答 1

4

It is highly recommended to put the 'use strict'; statement inside of a function - source.

Just wrap all of your code in an anonymous function (which is the recommended way of doing it).

(function() {
  "use strict";

  var app = angular.module('plunker', []);

  app.controller('MainCtrl', function($scope) {
    $scope.name = 'World';
  });

})();

Sample plunker: http://plnkr.co/edit/ShbhkuN3MXTHzmdrL3c5?p=preview

于 2014-09-19T16:27:14.387 回答