当我作为一个单独的页面导航到它时,showpost.html中的评论系统工作正常,但是当使用ng-include在post.html中包含showpost.html时,评论不会显示给我。有人看到我没有抓到的任何嵌套或范围问题吗?
这些的控制器位于app.js中,并且它没有检测到我在showpost.html中登录了// ng-hide =“signedIn()”//因为我签名时注释textarea出现了出。因此,当我包含页面时,ng-show和ng-hide正好与我期望的相反。
posts.html
<div class="ui comments">
<h3 class="ui dividing header">Latest posts</h3>
<div class="comment" ng-repeat="post in posts">
<a class="ui avatar image">
<img src="/images/avatar/guy.jpg">
</a>
<div class="content">
<a class="author"><a ng-href="#/users/{{ post.creatorUID }}"><b>{{ post.creator }}</b></a></span></a>
<div class="metadata">
<span class="date">Yesterday at 12:30AM</span>
</div>
<a ng-click="deletePost(post)" ng-show="user.uid === post.creatorUID" class="close-post"><i class="blue remove circle icon large"></i></a>
<div>
<a ng-href="{{ post.url }}">
{{ post.title }}</a><br><br>
<span class="url">{{ post.url | hostnameFromUrl }}</span>
<br><br>
</div>
<div class="actions">
<a class="reply" ng-href="#/posts/{{ post.$id }}">Add comment...</a>
</div>
</div><br>
<!-- COMMENTS NESTED -->
<div ng-include src="'views/showpost.html'"></div>
<!-- COMMENTS NESTED -->
</div>
</div>
showpost.html(评论页面)
<div class="container posts-page">
<div ng-repeat="comment in comments" class="row cmt">
<div class="col-md-12">
<p>{{ comment.text }}</p>
<p class="author">posted by <a ng-href="#/profile/{{ comment.creatorUID }}">{{ comment.creator }}</a>
<a ng-href="#/posts/{{ post.$id }}" ng-click="deleteComment(comment, $index)" ng-show="signedIn() && comment.creatorUID === user.uid">(delete)</a></p>
</div>
</div>
<div class="cmt-form">
<div ng-hide="signedIn()">
<p><a href="#/login">Sign in</a> to post a comment</p>
</div>
<form ng-show="signedIn()" ng-submit="addComment()">
<textarea ng-model="commentText" placeholder="Post a Comment" class="form-control"></textarea><br />
<input type="submit" value="Post Comment" class="btn btn-primary" />
</form>
</div>
</div>
app.js
/* global app:true */
/* exported app */
/* 'Firebase': false */
'use strict';
var app = angular
.module('devNews', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch',
'firebase'
])
.constant('FIREBASE_URL', 'https://sweltering-heat-8723.firebaseio.com/')
.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/posts.html',
controller: 'PostsCtrl'
})
.when('/posts/:postId', {
templateUrl: 'views/showpost.html',
controller: 'PostViewCtrl'
})
.when('/register', {
templateUrl: 'views/register.html',
controller: 'AuthCtrl',
// Resolve authentication of user before redirecting
resolve: {
// Define user property to inject into controller
user: function(Auth) {
return Auth.resolveUser();
}
}
})
.when('/login', {
templateUrl: 'views/login.html',
controller: 'AuthCtrl',
resolve: {
user: function(Auth) {
return Auth.resolveUser();
}
}
})
.when('/users/:userId', {
templateUrl: 'views/profile.html',
controller: 'ProfileCtrl'
})
.otherwise({
redirectTo: '/'
});
});