角构建不工作的服务器 [英] Angular build not working on server

查看:93
本文介绍了角构建不工作的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行我AngularJS在服务器前端。我使用的约曼来构建应用程序。我上传了非常基本的Hello World应用程序,我得到纯HTML文本withou的JavaScript加载。控制台在Chrome中这样说:

 错误:未知提供商:aProvider<  - 一个
    在错误(小于匿名>)
    在http://../scripts/vendor/d106​​39ae.angular.js:2627:15
    在Object.getService [如GET(HTTP://../scripts/vendor/d106​​39ae.angular.js:2755:39条)
    在http://../scripts/vendor/d106​​39ae.angular.js:2632:45
    在的getService(HTTP://../scripts/vendor/d106​​39ae.angular.js:2755:39)
    在调用(HTTP://../scripts/vendor/d106​​39ae.angular.js:2773:13)
    在Object.instantiate(HTTP://../scripts/vendor/d106​​39ae.angular.js:2805:23)
    在http://../scripts/vendor/d106​​39ae.angular.js:4620:24
    在更新(HTTP://../scripts/vendor/d106​​39ae.angular.js:13692:26)
    在http://../scripts/vendor/d106​​39ae.angular.js:8002:24 d10639ae.angular.js:5526

任何人都遇到同样的,知道的出路何在?

编辑:

 使用严格的;yoAngApp.controller('MainCtrl',['$范围,$窗口',函数($范围,$窗口){
    $ scope.awesomeThings = [
        HTML5样板,
        AngularJS',
        Testacular
    ];    $ scope.records = {[标题:一},{标题:两节},{标题:三化},{标题:'四'}]    $ scope.greet =功能(){
        ($ window.mockWindow || $窗口).alert('你好'+ $ scope.name);
    }
}]
);


解决方案

作为@ŁukaszBachman建议,你可以使用$注入注释,如果你想你可以使用内联诠释:


  1. 让您的依赖注解接近你的函数定义(可读性更好)。

  2. 远离污染全局命名空间了。

 

  app.controller('UsersController',
  [
    '$范围,UserService,$位置,$ routeParams',
    功能($范围,用户,$位置$ routeParams){
      $ scope.user = User.get({ID:$ routeParams.id});
      ...
    }
  ]
);

I am trying to run my AngularJS front-end on server. I am using Yeoman to build the app. I upload the very basic hello world app and I get plain HTML text withou JavaScript loaded. Console in Chrome says this:

Error: Unknown provider: aProvider <- a
    at Error (<anonymous>)
    at http://../scripts/vendor/d10639ae.angular.js:2627:15
    at Object.getService [as get] (http://../scripts/vendor/d10639ae.angular.js:2755:39)
    at http://../scripts/vendor/d10639ae.angular.js:2632:45
    at getService (http://../scripts/vendor/d10639ae.angular.js:2755:39)
    at invoke (http://../scripts/vendor/d10639ae.angular.js:2773:13)
    at Object.instantiate (http://../scripts/vendor/d10639ae.angular.js:2805:23)
    at http://../scripts/vendor/d10639ae.angular.js:4620:24
    at update (http://../scripts/vendor/d10639ae.angular.js:13692:26)
    at http://../scripts/vendor/d10639ae.angular.js:8002:24 d10639ae.angular.js:5526

Anybody experiencing the same and knows the way out?

EDIT:

'use strict';

yoAngApp.controller('MainCtrl',['$scope', '$window', function($scope, $window) {
    $scope.awesomeThings = [
        'HTML5 Boilerplate',
        'AngularJS',
        'Testacular'
    ];

    $scope.records = [{ title : 'one' }, { title : 'two' }, { title : 'three' }, { title : 'four' }];

    $scope.greet = function() {
        ($window.mockWindow || $window).alert('Hello ' + $scope.name);
    }
}]
);

解决方案

As @ŁukaszBachman suggested, you may use $inject annotation or you may use Inline Annotation if you want to:

  1. Keep your dependency annotations close to your function definitions (for better readability).
  2. Stay away from polluting global namespace.

 

app.controller('UsersController',
  [
    '$scope', 'UserService', '$location', '$routeParams',
    function($scope, User, $location, $routeParams) {
      $scope.user = User.get({id: $routeParams.id});
      ...
    }
  ]
);

这篇关于角构建不工作的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆