gpt4 book ai didi

javascript - 错误 : [ng:areq] Argument is not a function, 未定义,关于 thinkster.io 的教程

转载 作者:行者123 更新时间:2023-11-29 19:30:43 27 4
gpt4 key购买 nike

<分区>

[更新]这是我的一个愚蠢的错字。谢谢 dfsq!

这里有一个类似的问题,我的代码遵循了推荐的答案,所以请不要将其标记为重复。

在我的本地主机中,出现以下错误:Error: [ng:areq] Argument 'PostCtrl' is not a function, got undefined

app.js 的内容:

/* global app:true */
/* exported app */
'use strict';

var app = angular
.module('redjsApp', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch',
'firebase'
])
.constant('FIREBASE_URL', 'https://blazing-fire-6602.firebaseio.com/')
.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/posts.html',
controller: 'PostCtrl'
})
.when('/about', {
templateUrl: 'views/about.html',
controller: 'AboutCtrl'
})
.otherwise({
redirectTo: '/'
});
});

scripts/services/post.js 的内容:

'use strict';

app.factory('Post', function ($firebase, FIREBASE_URL) {
var ref = new Firebase(FIREBASE_URL + 'posts');
var posts = $firebase(ref.child('posts')).$asArray();
console.log($firebase(ref.child('posts')).$asArray());

var Post = {
all: posts,
create: function (post) {
return posts.$add(post);
},
get: function (postId) {
return $firebase(ref.child('posts').child(postId)).$asObject();
},
delete: function (post) {
return posts.$remove(post);
}
};

return Post;

});

scripts/posts.js 的内容:

'use strict';

app.controller('PostsCtrl', function ($scope, Post) {
$scope.posts = Post.all;

$scope.post = {url: 'http://', 'title': ''};

$scope.submitPost = function () {
Post.create($scope.post).then(function () {
$scope.post = {url: 'http://', 'title': ''};
});
};

$scope.deletePost = function (post) {
Post.delete(post);
};

});

posts.html 的内容是:

<div ng-repeat="post in posts">
<a ng-href="{{ post.url }}">{{ post.title }}</a>
<a ng-click="deletePost(post)">delete</a>
</div>
</div>
<form ng-submit="submitPost()">
<input type="text" ng-model="post.title" />
<input type="text" ng-model="post.url" />
<input type="submit" value="Add Post" />
</form>
Posts: {{ posts}} <br />
Post: {{post}}

仅呈现 html,不呈现任何关联的 js。该应用程序是使用 yeoman 构建的。帮助将不胜感激!

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com