Use Closure Compiler with AngularJS in ADVANCED_MODE

久未见 提交于 2019-12-06 10:05:27
  1. Add @ngInject in jsdocs of the controller constructor function,
  2. Pass in the function as an argument to angular module app.controller('myCtrl', fn)
  3. Make sure to pass in --angular_pass argument to the closure compiler.

So, here is a modified version of the provided example that should work for you:

goog.provide("vmap");

/**
 * @constructor
 * @ngInject
 */
vmap = function($scope) {
    $scope.firstName= "John";
    $scope.lastName= "Doe";
};


var app = angular.module('myApp', []);
app.controller('myCtrl', vmap);

Write you controller using the array notation:

app.controller('myCtrl', ['$scope', function($scope) {
    $scope['firstName'] = "John";
    $scope['lastName'] = "Doe";
}]);

As local variables (like $scope) get renamed, and object properties ($scope.firstName) too, unless you write them using the string notation.

More information about minification in AngularJS here: https://docs.angularjs.org/tutorial/step_05#a-note-on-minification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!