简体   繁体   English

角度$ scope功能未更新

[英]Angular $scope not updating in function

I have a strange problem with Angulars scope. 我对Angulars范围有一个奇怪的问题。 I worked with it for a while and everything is great, but in this little snippet the $scope will not change. 我使用了一段时间,一切都很好,但是在这个小片段中,$ scope不会改变。 Any idea? 任何想法? ($scope.projects and $scope.commentText, the post returns the data successfully) ($ scope.projects和$ scope.commentText,该帖子成功返回数据)

Model from HTM: 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>

Controller: 控制器:

$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);

            });
    }

I figured it out. 我想到了。 Everything was working fine...the problem is I can't change the content of the textarea with the commong $scope.textarea = "". 一切工作正常...问题是我无法使用commong $ scope.textarea =“”更改textarea的内容。

I used jquery with $("#text-area").val("") for this. 我为此使用$(“#text-area”)。val(“”)的jquery。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM