gpt4 book ai didi

javascript - angularjs 数据绑定(bind)问题

转载 作者:行者123 更新时间:2023-11-30 16:24:10 25 4
gpt4 key购买 nike

我正在尝试允许用户提交评论,并在其中显示评论。但是,它似乎无法正常工作,因为我能够将其显示为预览,但是当我提交时,它不会保存为包含其他评论的数组。调试后,我发现它绑定(bind)到我的 $scope.review,但它作为网页上显示的空白默认格式提交到我的数组。源代码可以在 http://plnkr.co/edit/q5fRIG6DzTegi3Ir1y8G?p=preview 找到。 . (注释掉原始状态和范围的重置,这也给出了同样的错误)。

Javascript

    .controller('DishCommentController', ['$scope', function($scope) {

$scope.review = {name:"", rating:"Five", comment:"",date:""};
$scope.submitComment = function () {

$scope.review.date = new Date().toISOString();

// Push comment into the dish's comment array
$scope.dish.comments.push("$scope.review");
//reset form to pristine
// $scope.commentForm.$setPristine="";
//reset JavaScript object that holds your comment
// $scope.review = {name:"", rating:"Five", comment:"",date:""};
}

HTML

        <div class="media-list">
<ul ng-show="!commentForm.comment.$error.required && !commentForm.comment.$pristine && !commentForm.name.$error.required && !commentForm.name.$pristine">
<blockquote>
<p>{{review.rating}} Stars</p>
<p>{{review.comment}}</p>
<footer>By {{review.name}} on {{review.date | date:'mediumDate'}} </footer>
</blockquote>
</ul>
</div>

最佳答案

你需要插入对象:

$scope.dish.comments.push($scope.review);

关于javascript - angularjs 数据绑定(bind)问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34347063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com