0
我想显示的帖子表本教程如下:从火力地堡与显示数据的角度
5部分仍未公布,所以我把教程一路部分4并试图建立一个post.html视图。然而,作为角度和火力基础的初学者,我真的很挣扎。
这里是我的岗位/ post.js文件中的代码:
'use strict';
angular.module('myApp.post', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/post', {
templateUrl: 'post/post.html',
controller: 'PostCtrl'
});
}])
.controller('PostCtrl', ['$scope','$firebase' , function($scope,$firebase) {
$scope.message = 'Hello World';
$scope.viewPost = function(){
$scope.article.title = "";
$scope.article.post = "";
$scope.article= {};
$scope.myData = new Firebase("https://glowing-fire-6133.firebaseio.com/Posts");
};
$scope.myData.on('value', function(snapshot){
$scope.article = snapshot.val();
});
}]);
这里是我的post.html文件的代码
<title></title>
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/css/blog.css" rel="stylesheet">
</head>
<body ng-controller="PostCtrl">
<h1>{{message}}</h1>
<div ng-repeat="post in posts">
<h2>{{article.title}}</h2>
<div>{{article.post}}</div>
</div>
</body>
</html>
我从此没有任何错误或结果。我确信添加
'myApp.post', //Post view
模块app.js,并在index.html的,但仍然没有在。
我在做或失去一些真正愚蠢的东西吗? I.E.登录到数据库等?
感谢您的耐心
## Addpost脚本'use strict';
angular.module('myApp.addPost', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/addPost', {
templateUrl: 'addPost/addPost.html',
controller: 'AddPostCtrl'
});
}])
.controller('AddPostCtrl', ['$scope','$firebase',function($scope,$firebase) {
$scope.AddPost = function(){
var title = $scope.article.title;
var post = $scope.article.post;
var firebaseObj = new Firebase("https://glowing-fire-6133.firebaseio.com/Posts");
var fb = $firebase(firebaseObj);
fb.$push({ title: title,post: post}).then(function(ref) {
console.log(ref);
}, function(error) {
console.log("Error:", error);
});
}
}]);
感谢您的回复。我理解你的观点,但是如何让myData成为一堆$ scope.posts对象?我需要按照myData.items做些什么吗? – HGB 2015-04-05 18:38:23
@Cigana它看起来像myData是一堆post对象给我。不是吗?无可否认,我不知道Firebase,但是这个url看起来像一个返回post对象的控制器的请求。你能展示你从中得到的JSON吗? – Yatrix 2015-04-06 01:30:57
是的,你是正确的,这是一堆对象,我只是不明白怎么能在一个对象中请求它。 firebase格式类似于Json的对象的方式如下:'glowing-fire-6133'(db name) 'Jm9nJDRrIq9Dncfj1gv'(表I相信) 'post:post content' 'title:post title' – HGB 2015-04-06 20:25:24