Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在高级_模式下将闭包编译器与AngularJS一起使用_Javascript_Angularjs_Google Closure Compiler - Fatal编程技术网

Javascript 在高级_模式下将闭包编译器与AngularJS一起使用

Javascript 在高级_模式下将闭包编译器与AngularJS一起使用,javascript,angularjs,google-closure-compiler,Javascript,Angularjs,Google Closure Compiler,我正试图编译一个angular&openLayers项目,但我不能使用angular 我已经输入了angular外部参数,但编译后出现以下错误: Error: [$injector:unpr] Unknown provider: aProvider <- a <- myCtrl http://errors.angularjs.org/1.3.15/$injector/unpr?p0=aProvider%20%3C-%20a%20%3C-%20myCtrl at REGEX_S

我正试图编译一个angular&openLayers项目,但我不能使用angular

我已经输入了angular外部参数,但编译后出现以下错误:

Error: [$injector:unpr] Unknown provider: aProvider <- a <- myCtrl
http://errors.angularjs.org/1.3.15/$injector/unpr?p0=aProvider%20%3C-%20a%20%3C-%20myCtrl
    at REGEX_STRING_REGEXP (angular.js:63)
    at angular.js:4015
    at Object.getService [as get] (angular.js:4162)
    at angular.js:4020
    at getService (angular.js:4162)
    at Object.invoke (angular.js:4194)
    at $get.extend.instance (angular.js:8493)
    at angular.js:7739
    at forEach (angular.js:331)
    at nodeLinkFn (angular.js:7738)
要编译这些文件,我使用以下命令:

python closure-library/closure/bin/build/closurebuilder.py
--root=closure-library/ 
--root=../debug/ 
--namespace="vmap" 
--output_mode=compiled 
--compiler_jar=compiler.jar 
--compiler_flags="
    --compilation_level=ADVANCED_OPTIMIZATIONS" 
    --compiler_flags="--externs=../debug/lib/angular/angular-1.3.js" 
    --compiler_flags="--angular_pass" > ../vmap.js
我找到了angular-1.3.js文件


我错过了什么?

使用数组表示法编写控制器:

app.controller('myCtrl', ['$scope', function($scope) {
    $scope['firstName'] = "John";
    $scope['lastName'] = "Doe";
}]);
由于局部变量(如$scope)被重命名,对象属性($scope.firstName)也被重命名,除非您使用字符串表示法编写它们

有关AngularJS缩小的更多信息,请参见:

  • 在控制器构造函数的jsdocs中添加
    @ngInject
  • 将函数作为参数传递给角度模块
    app.controller('myCtrl',fn)
  • 确保将
    --angular\u pass
    参数传递给闭包编译器
  • 因此,这里是所提供示例的一个修改版本,应该适合您:

    goog.provide(“vmap”);
    /**
    *@constructor
    *@ngInject
    */
    vmap=功能($scope){
    $scope.firstName=“John”;
    $scope.lastName=“Doe”;
    };
    var-app=angular.module('myApp',[]);
    应用控制器('myCtrl',vmap);
    
    看起来您正在缩小代码,但角度代码的编写方式不允许缩小。看看这篇博文,它涵盖了可以缩小的角度代码
    python closure-library/closure/bin/build/closurebuilder.py
    --root=closure-library/ 
    --root=../debug/ 
    --namespace="vmap" 
    --output_mode=compiled 
    --compiler_jar=compiler.jar 
    --compiler_flags="
        --compilation_level=ADVANCED_OPTIMIZATIONS" 
        --compiler_flags="--externs=../debug/lib/angular/angular-1.3.js" 
        --compiler_flags="--angular_pass" > ../vmap.js
    
    app.controller('myCtrl', ['$scope', function($scope) {
        $scope['firstName'] = "John";
        $scope['lastName'] = "Doe";
    }]);