Thinkster.io Angularjs教程第3章 - 问题连接到火力地堡 [英] Thinkster.io Angularjs tutorial Chapter 3 - Problems connecting to Firebase

查看:290
本文介绍了Thinkster.io Angularjs教程第3章 - 问题连接到火力地堡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面的<一个href=\"http://www.thinkster.io/angularjs/S2MxGFCO0B/3-communicating-with-a-server-using-a-service-and-resource\"相对=nofollow>本教程,建设angularjs应用与连接到数据库的火力点。我被困在那里我的应用程序应该使其数据库的初始连接第3章。我有点觉得,问题是在我的面前,因为我的命令提示符并jshint告诉我:

I'm following this tutorial, building an angularjs app with connection to the firebase database. I'm stuck at chapter 3 where my app is supposed to make it initial connection to the database. I kind of felt that problems were in front of me since my command prompt and jshint tells me:

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.

我的控制台给我:

My console gives me:

>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">


为什么不是由我的其他JS-文件见过我的应用全局声明?


Why isn't my global declaration of 'app' seen by my other js-files?

(apps.js)

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

(post.js)

(post.js)

'use strict';
app.factory('Post', function ($resource){
return $resource('https://sizzling-fire-1990.firebaseio.com/posts/:id.json');
});

**内容从本教程复制所有文件

**All files content are copied from the tutorial

推荐答案

我有同样的问题做教程,和它的becouse你做了没有,这一步说道:

I had the same problem doing the tutorial, and It's becouse you did no that it step says:

如果你看看你的咕噜终端,可以看到有正在运行的每更改一个JavaScript文件时间的任务称为jshint。这将检查你的JavaScript任何语法错误,并给你的提示修复它们在理想情况下,我们希望在我们的应用程序没有错误在.jshintrc,我们可以添加应用程序:虚假讲述应用jshint所以我们可以利用它在我们的所有文件,没有任何警告,和/ 的全球应用程序:真正的 /在app.js让jshint知道,应用程序是在该文件中定义的顶部

"If you look at your grunt terminal, you can see that there's a task called jshint that is run every time you change a javascript file. This checks your javascript for any syntax errors and gives you hints for fixing them. Ideally we want to have no errors in our application. In .jshintrc, we can add "app": false to tell jshint about app so we can use it in all of our files without any warnings, and / global app:true / at the top of app.js to let jshint know that app is defined in that file."

应用程序一样不是全局变量,你需要添加它,所以你Jshintrc文件如下:

Like app is not global variable, you need add it, So you Jshintrc File looks like:

{

  "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
  }
}

和App.Js:

'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'
  ])....

另外添加&LT;脚本的src =脚本/服务/ post.js&GT;&LT; / SCRIPT&GT; 页面

我觉得你的问题是,

这篇关于Thinkster.io Angularjs教程第3章 - 问题连接到火力地堡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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