我有一個Angulars範圍的奇怪問題。我與它合作了一段時間,一切都很好,但在這個小小的片段中,$範圍不會改變。任何想法? ($ scope.projects和$ scope.commentText,後成功返回的數據)HTM
型號:
<textarea ng-model="commentText" class="form-control"
placeholder="Enter your comment..." rows="3"></textarea>
<br>
<a href="#" class="btn btn-primary btn-sm pull-right" ng-click="postComment(projects[0]._id, commentText)">Post comment</a>
控制器:
$scope.postComment = function (project_id, comment) {
console.log(project_id, comment);
if (comment && $scope.user) {
var body = {
project: project_id,
text: comment.replace(/\r?\n/g, '<br />'),
user: $scope.user.nickname,
date: new Date()
};
$http.post('/api/projects/comment', body)
.success(function (data) {
data.comments.map(function (comment) {
comment.text = $sce.trustAsHtml(comment.text)
});
$scope.projects[0] = data;
$scope.commentText = "";
})
.error(function (error) {
console.log('Error: ' + error);
});
}
你能在小提琴中重現嗎? –
我不得不減少一點,但它在那裏工作。 http://jsfiddle.net/ADukg/9756/ –
代碼是正確的只是檢查你是否成功回調你在$ sce.trustAsHtml(comment.text)中做什麼試圖在$ sce依賴於控制器和它的包括圖書館至少沒有看到小提琴? –