AngularJS - 未知提供商 [英] AngularJS - Unknown Provider

查看:220
本文介绍了AngularJS - 未知提供商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个使用AngularJS小笔记应用程序,但我在开始的时候绊倒了。这是我的.js文件:

I'm trying to create a small note-taking application using AngularJS, but I stumbled at the very beginning. Here's my .js file:

var app = angular.module("app", ['ngResource']);

app.factory("note", ['$resource', function($resource){
    return $resource("/api/notes/:id", {id:'@id'}, {
        query: {method: "GET", isArray: true}});
        }
    ]
);

app.controller("NotesController", function($scope, $note){
    console.log("I am being constructed");
    $scope.notes = $note.query();
});

和这里的HTML文件:

And here's the html file:

<html>
<head>
    <title>Jotted</title>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
    <script src="js/controllers/controllers.js"></script>
    <script src="http://code.angularjs.org/1.0.6/angular-resource.js"></script>
    <link href='style/main.css' rel='stylesheet'>
</head>
<body ng-app="app" >
    <div ng-controller="NotesController">
        <div ng-repeat="note in notes">
            {{note.title}}
        </div>          
    </div>
</body>
</html>

我已经尝试添加

NotesController.$inject("$scope", "Note");

但只给马一个错误说,NotesController没有命名的方法$注入。

but it only gave ma an error saying that NotesController does not have a method named "$inject".

无任何显示在浏览器返回一个错误:错误:未知提供商:$ noteProvider&LT; - $注意。当然,我失去了一些东西很明显,但我不能把我的手指上。哪里的问题出在哪里?

Nothing is displayed and the browser returns an error: "Error: Unknown provider: $noteProvider <- $note". Certainly I am missing something obvious, but I can't put my finger on it. Where does the problem lie?

推荐答案

您$音符之前删除$符号。美元符号仅仅是框架公约,以确定内部提供商,...。

Remove the $ Sign before your $note. The dollar Sign is only a convention of the Framework to identify internal Providers,... .

例如尝试:

var app = angular.module("app", ['ngResource']);

app.factory("note", ['$resource', function($resource){
    return $resource("/api/notes/:id", {id:'@id'}, {
        query: {method: "GET", isArray: true}});
        }
    ]
);

app.controller("NotesController", function($scope, note){
    console.log("I am being constructed");
    $scope.notes = note.query();
});

这篇关于AngularJS - 未知提供商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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