$ http和$范围的变量在模板不显示 [英] $http and $scope variable not showing in template
本文介绍了$ http和$范围的变量在模板不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
变量 $ scope.discussionId
不在我的模板呈现。每隔值显示
The variable $scope.discussionId
is not showing in my template. Every other value are displaying
我在做什么错了?
编辑(全code)
控制器
soundshareApp.controller('CommentController', function($scope, $http) {
$scope.data = { comments : [] }
$scope.state = {}
$scope.project = { id : [] }
$scope.discussionId;
$scope.test = "Hello World !";
$scope.loadComments = function(userName, urlName){
$http({
url: '/comment/by_project_id',
method: "GET",
params:
{
username: userName,
urlname: urlName
}
}).success(function(data) {
$scope.discussionId = data[0].discussionId;
console.log("discussionId " + $scope.discussionId);//display the value !!
$scope.data.comments = data;
});;
}
}
模板
<div ng-controller="CommentController" >
<div class='message-content' ng-click="state.show = !state.show">
<img class='message-vignette' ng-src='{{commentData.avatarUrl}}'/>
<div class='message-username'>{{commentData.username}}</div>
<div class='project-message'> {{commentData.comment}}</div>
<div class='message-date'>{{commentData.dateCreated | date:'MM/dd/yyyy @ h:mma' }}</div>
</div>
<div class="answer-message-content show-hide" ng-show="state.show" >
<img class='message-vignette answer-message-vignette' ng-src='{{commentData.currentUserAvatarUrl}}'>
<div class="add-comment-content">
<form ng-submit="addComment(commentData)" id="commentForm-{{commentData.projectId}}">
<input id="input-comment-{{commentData.projectId}}" type="text" maxlength="255" name="comment" placeholder="Write a comment..." ng-model="commentData.msg">
<input type="hidden" name="discussionId" value="{{commentData.discussionId}}" >
<input type="hidden" name="projectId" value="{{commentData.projectId}}" >
</form>
</div>
</div>
test : {{test}}// showing "Hello World!"
discussionId: {{discussionId}}//not showing !!
<div ng-repeat="answer in answers" class="answer-message-content">
<div class='message-content' ng-click="state.show = !state.show">
<img class='message-vignette' ng-src='{{answer.avatarUrl}}'/>
<div class='message-username'>{{answer.username}}</div>
<div class='project-message'> {{answer.comment}}</div>
<div class='message-date'>{{answer.dateCreated | date:'MM/dd/yyyy @ h:mma' }}</div>
</div>
</div>
</div>
MAIN(Grails的GSP)
<div ng-init="loadComments('${params.username}', '${params.urlname}' )">
<div ng-repeat="pdata in data.comments" >
<div sdcomment param="pdata"></div>
</div>
</div>
指令
soundshareApp.directive('sdcomment', function(){
return {
restrict:'A',
scope: {
commentData: '=param'
},
templateUrl: '/js/views/comment/templates/commentList.html',
link : function(scope, elem, attrs) {
}
}
});
感谢您
推荐答案
我不明白 $ scope.loadComments
被称为有史以来。 $ scope.discussionId;
是初始化定义。如果你初始化我敢打赌,你就会显示该值,是这样的:
I do not see $scope.loadComments
gets ever called. $scope.discussionId;
is initialize undefined. if you initialize it I bet you it will display that value, something like:
$scope.discussionId = 10;
这篇关于$ http和$范围的变量在模板不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文