我一直在學習角最近和創建引用一個新的網站我有一個教程中創建的過程。按照我被告知的所有步驟,出於某種原因,我得到這個錯誤。奇怪的是,它顯示爲某種網址。這裏的「錯誤」:角控制器是不是一個函數,得到了不確定
http://errors.angularjs.org/1.4.9/ng/areq?p0=PostCtrl&p1=not%20a%20function%2C%20got%20undefined
刪除所有url亂碼葉子PostCtrl不是一個函數得到了undefined。
我不明白爲什麼,我找遍了整個堆棧溢出和所有的常見錯誤,例如使用全球範圍內,不登記控制器,而且似乎其他常見的錯誤不會是原因。這是控制器和玉文件。
控制器:
var app = angular.module("app", []);
(function() {
var PostCtrl = function ($scope, $log, $location) {
$scope.posts = [];
$scope.post = function (title, content) {
$scope.title = title;
$scope.content = content;
$log.info("Posting article: " + title + "\n" + content);
$scope.posts.push([title, content]);
};
};
app.controller("PostCtrl", ["$scope", "$log", PostCtrl]);
})();
玉文件:(NG-應用= 「APP」)是佈局文件內,與所有其他的腳本涉及角沿。
extends partials/layout
block scripts
script(src="app/controllers/PostCtrl.js")
block content
.body(ng-controller="PostCtrl")
.row
.col-xs-12
form(class="form-horizontal" ng-submit="post(title, content)")
.form-group
label(for="inputTitle" class="col-sm-2 control-label") Title
.col-sm-10
input(type="text" class="form-control" id="inputTitle" placeholder="Title" ng-model="title")
.form-group
label(for="inputContent" class="col-sm-2 control-label") Content
.col-sm-10
textarea(class="form-control" id="inputContent" placeholder="Content" ng-model="content")
.form-group
.col-sm-offset-2.col-sm-10
button(type="submit" class="btn btn-default") Post
hr
.row
.col-xs-12
你忘一個依賴在創建角控制器'app.controller的( 「PostCtrl」,[ 「$範圍」, 「$日誌」,PostCtrl]);'=>'」 $ location「'丟失。 – FlorianTopf
有趣的是,$ location是默認的依賴項嗎?我一定忘記了,但不記得馬上使用它。 – Jordan
你是否有這樣一行'var app = angular.module(「app」,[]);'它是你的其他腳本,在'app.js'還是其他地方? – oKonyk