0

嗨,我正在 MEAN 堆栈上创建一个简单的轮询应用程序。我正在使用本教程来创建我的应用程序。我目前刚刚完成第 3 步,但我的应用程序没有按预期运行。

当我在 Eclipse 中调试时,我收到的是:

Jshint 告诉我,我的 services.js、app.js、controller.js 中没有定义 Angular。正如其他示例所建议的那样,我已经尝试将脚本标签移动到各处,以各种顺序重新排列它们,但没有一个删除此错误。

编辑我已将来自 jack_the_ripper 的信息包含到我的 .jshintrc 文件中。我相信我仍然做错了什么。这是我要求的代码副本。

{    
"bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.).
"curly" : true, // Require {} for every new block or scope.
"eqeqeq" : true, // Require triple equals i.e. `===`.
"forin" : true, // Tolerate `for in` loops without `hasOwnPrototype`.
"immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
"latedef" : true, // Prohibit variable use before definition.
"newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`.
"noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
"noempty" : true, // Prohibit use of empty blocks.
"nonew" : true, // Prohibit use of constructors for side-effects.
"plusplus" : false, // Prohibit use of `++` & `--`. //coding style related only
"regexp" : true, // Prohibit `.` and `[^...]` in regular expressions.
"undef" : true, // Require all non-global variables be declared before they are used.
"strict" : false, // Require `use strict` pragma in every file.
"trailing" : true, // Prohibit trailing whitespaces.


"asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons).
"boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
"debug" : false, // Allow debugger statements e.g. browser breakpoints.
"eqnull" : false, // Tolerate use of `== null`.
"es5" : true, // Allow EcmaScript 5 syntax. // es5 is default https://github.com/jshint/jshint/issues/1411
"esnext" : false, // Allow ES.next (ECMAScript 6) specific features such as `const` and `let`.
"evil" : false, // Tolerate use of `eval`.
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
"funcscope" : false, // Tolerate declarations of variables inside of control structures while accessing them later from the outside.
"globalstrict" : false, // Allow global "use strict" (also enables 'strict').
"iterator" : false, // Allow usage of __iterator__ property.
"lastsemic" : false, // Tolerat missing semicolons when the it is omitted for the last statement in a one-line block.
"laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
"laxcomma" : true, // Suppress warnings about comma-first coding style.
"loopfunc" : false, // Allow functions to be defined within loops.
"maxerr" : 100, // This options allows you to set the maximum amount of warnings JSHint will produce before giving up. Default is 50.
"moz" : false, // This options tells JSHint that your code uses Mozilla JavaScript extensions. Unless you develop specifically for the Firefox web browser you don't need this option.
"multistr" : false, // Tolerate multi-line strings.
"onecase" : false, // Tolerate switches with just one case.
"proto" : false, // Tolerate __proto__ property. This property is deprecated.
"regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`.
"scripturl" : false, // Tolerate script-targeted URLs.
"smarttabs" : false, // Tolerate mixed tabs and spaces when the latter are used for alignmnent only.
"shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
"sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
"supernew" : false, // Tolerate `new function () { ... };` and `new Object;`.
"validthis" : false, // Tolerate strict violations when the code is running in strict mode and you use this in a non-constructor function.
"couch" : false, // Enable globals exposed by CouchDB.
"devel" : false, // Allow development statements e.g. `console.log();`.
"dojo" : false, // Enable globals exposed by Dojo Toolkit.
"jquery" : false, // Enable globals exposed by jQuery JavaScript library.
"mootools" : false, // Enable globals exposed by MooTools JavaScript framework.
"node" : true, // Enable globals available when code is running inside of the NodeJS runtime environment.
"nonstandard" : false, // Define non-standard but widely adopted globals such as escape and unescape.
"phantom" : false, //?since version? This option defines globals available when your core is running inside of the PhantomJS runtime environment.
"prototypejs" : false, // Enable globals exposed by Prototype JavaScript framework.
"rhino" : false, // Enable globals available when your code is running inside of the Rhino runtime environment.
"worker" : false, //?since version? This option defines globals available when your code is running inside of a Web Worker.
"wsh" : false, // Enable globals available when your code is running as a script for the Windows Script Host.
"yui" : false, //?since version? This option defines globals exposed by the YUI JavaScript framework.

"nomen" : false, // Prohibit use of initial or trailing underbars in names.
"onevar" : false, // Allow only one `var` statement per function.
"passfail" : false, // Stop on first error.
"white" : false, // Check against strict whitespace and indentation rules.
"globals": { // Globals variables.
    "jasmine": true,
    "angular": true,
    "ApplicationConfiguration": true,
    "browser": true,
    "element": true,
    "io":true,
    "_":false,
    "$":false
    }

    }

我收到的另一个错误是当我尝试在 chrome 中检查时。控制台响应:

错误:[$resource:badcfg] 操作的资源配置错误query。预期的响应包含一个数组但得到了一个对象。我确实相信这是我的麻烦的根源。它位于 .\public\js\services.js 文件中,但是尽管到目前为止我已经测试了许多在线提供的解决方案,但一直未能找到解决此错误的方法。

Edit2我的 services.js 代码不起作用。

     angular.module('pollServices', ['ngResource']).
      factory('Poll', function($resource) {
        return $resource('polls/:pollId', {}, {
          query: { method: 'GET', params: { pollId: 'polls' }, isArray: true }
        });
      });

当我在 Batarang 中检查它时,我的模型在民意调查列表范围内始终为空,即使在我创建它们之后也是如此。

如果您有空闲时间并且不介意查看我的代码,我已将其上传到此git 存储库

提前感谢您的时间。

真挚地,

弗雷德克

4

1 回答 1

0

您应该只将您的应用程序的相关代码包含在问题中,因为如果您缩小范围,更容易发现问题,无论如何,您似乎遇到了一些常见问题,作为 angular.js 开发人员,您会经常发现.

我在引用你的问题:

Jshint 告诉我 Angular 没有在我的 services.js、app.js、controller.js 中定义。正如其他示例所建议的那样,我已经尝试将脚本标签移动到各处,以各种顺序重新排列它们,但没有一个删除此错误。

在根文件夹中创建一个名为.jshintrc的文件,将 angular 添加到全局变量中,如下所示:

"globals": { // Globals variables.
        "jasmine": true,
        "angular": true,
        "ApplicationConfiguration": true,
        "browser": true,
        "element": true,
        "io":true,
        "_":false,
        "$":false
    }

操作查询的资源配置错误。预期的响应包含一个数组但得到了一个对象。

这是一个常见的场景,当你查询你的 REST API 并且你应该配置你的$resource服务来检索一个数组或单个对象,在你的情况下你应该在你的配置中使用isArray: false,有关更多信息,请查看有关如何设置$resource的资源文档

于 2014-12-02T16:34:02.270 回答