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';
   });
Dmitry
  • 4,143
  • 10
  • 46
  • 57

1 Answers1

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

Community
  • 1
  • 1
JoseM
  • 4,302
  • 2
  • 24
  • 35