Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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 Thinkster.io Angularjs教程第3章-连接Firebase的问题_Javascript_Angularjs_Gruntjs_Firebase - Fatal编程技术网

Javascript Thinkster.io Angularjs教程第3章-连接Firebase的问题

Javascript Thinkster.io Angularjs教程第3章-连接Firebase的问题,javascript,angularjs,gruntjs,firebase,Javascript,Angularjs,Gruntjs,Firebase,我正在学习教程,构建一个连接firebase数据库的angularjs应用程序。我被困在第三章,在那里我的应用程序应该与数据库建立初始连接。我觉得问题就在眼前,因为我的命令提示符和jshint告诉我: Running "jshint:all" (jshint) task app\scripts\controllers\posts.js line 0 col 0 Bad option: 'app'. line 8 col 1 'app' is not defined. ap

我正在学习教程,构建一个连接firebase数据库的angularjs应用程序。我被困在第三章,在那里我的应用程序应该与数据库建立初始连接。我觉得问题就在眼前,因为我的命令提示符和jshint告诉我:

Running "jshint:all" (jshint) task

app\scripts\controllers\posts.js
  line 0   col 0  Bad option: 'app'.
  line 8   col 1  'app' is not defined.

app\scripts\services\post.js
  line 0   col 0  Bad option: 'app'.
  line 2   col 1  'app' is not defined.

6 problems

Warning: Task "jshint:all" failed. Use --force to continue.

Aborted due to warnings.
我的控制台给了我:

>Uncaught ReferenceError: app is not defined                      post.js
>Error: [$injector:unpr] Unknown provider: PostProvider <- Post
http://errors.angularjs.org/1.2.16/$injector/unpr?p0=PostProvider%20%3C-%20Post at http://localhost:9000/bower_components/angular/angular.js:78:12
at http://localhost:9000/bower_components/angular/angular.js:3705:19
at Object.getService [as get] (http://localhost:9000/bower_components/angular/angular.js:3832:39)
at http://localhost:9000/bower_components/angular/angular.js:3710:45
at getService (http://localhost:9000/bower_components/angular/angular.js:3832:39)
at invoke (http://localhost:9000/bower_components/angular/angular.js:3859:13)
at Object.instantiate (http://localhost:9000/bower_components/angular/angular.js:3880:23)
at http://localhost:9000/bower_components/angular/angular.js:7134:28
at link (http://localhost:9000/bower_components/angular-route/angular-route.js:913:26)
at nodeLinkFn (http://localhost:9000/bower_components/angular/angular.js:6579:13) <div ng-view="" class="ng-scope">
(post.js)


**所有文件内容都是从教程中复制的

我在编写教程时遇到了相同的问题,这是因为您没有这样做,步骤中说:

“如果您查看grunt终端,您可以看到每次更改javascript文件时都会运行一个名为jshint的任务。这将检查您的javascript是否存在语法错误,并为您提供修复这些错误的提示。理想情况下,我们希望应用程序中没有错误。在.jshintrc中,我们可以添加”app““:false告诉jshint关于app的信息,这样我们就可以在所有文件中使用它,而不会出现任何警告;以及/global app:true/在app.js的顶部,让jshint知道app是在该文件中定义的。”

如果app不是全局变量,则需要添加它,因此Jshintrc文件如下所示:

{

  "node": true,
  "browser": true,
  "esnext": true,
  "bitwise": true,
  "camelcase": true,
  "curly": true,
  "eqeqeq": true,
  "immed": true,
  "indent": 2,
  "latedef": true,
  "newcap": true,
  "noarg": true,
  "quotmark": "single",
  "regexp": true,
  "undef": true,
  "unused": true,
  "strict": true,
  "trailing": true,
  "smarttabs": true,
  "globals": {
    "angular": false,
    "app":false <---- Add this line
  }
}
{
“节点”:正确,
“浏览器”:正确,
“esnext”:没错,
“按位”:正确,
“骆驼案”:没错,
“卷曲”:没错,
“EQEQ”:对,
“伊梅德”:没错,
“缩进”:2,
“latedef”:没错,
“newcap”:没错,
“诺格”:没错,
“quotmark”:“single”,
“regexp”:正确,
“未定义”:正确,
“未使用”:正确,
“严格”:是的,
“拖尾”:正确,
“智能标签”:正确,
“全球”:{
“棱角”:假,

“app”:false Thank,great help!这解决了命令提示符中的警告和错误消息。我还将“”添加到index.html文件中以包含脚本。(教程中对此进行了描述,但我错过了该部分)哦!!!是的,我忘了。请仔细阅读所有教程,因为有时不向您显示代码,只显示说明。:)教程消息不够清楚,我无法正确添加这两条语句。@Stephaneybert确切地说。他们没有指定“确切地”将这两行代码放置在何处。大多数问题的解决方案都在o官方文件,谢谢兄弟
'use strict';
app.factory('Post', function ($resource){
return $resource('https://sizzling-fire-1990.firebaseio.com/posts/:id.json');
});
{

  "node": true,
  "browser": true,
  "esnext": true,
  "bitwise": true,
  "camelcase": true,
  "curly": true,
  "eqeqeq": true,
  "immed": true,
  "indent": 2,
  "latedef": true,
  "newcap": true,
  "noarg": true,
  "quotmark": "single",
  "regexp": true,
  "undef": true,
  "unused": true,
  "strict": true,
  "trailing": true,
  "smarttabs": true,
  "globals": {
    "angular": false,
    "app":false <---- Add this line
  }
}
'use strict';
/* global app:true */ <---- Add this line


/**
 * @ngdoc overview
 * @name angNewsApp
 * @description
 * # angNewsApp
 * 
 * Main module of the application.
 * 
 */


var app = angular.module('angNewsApp', [
    'ngCookies',
    'ngResource',
    'ngRoute',
    'ngSanitize'
  ])....