我正在尝试模拟审查系统。ng 如何将传递值提交给控制器?
在我的控制器中,我有
$scope.reviews = function() {
$scope.rating = 0;
$scope.max = 5;
};
$scope.myTextArea = '';
$scope.saveReview = function(rating, myTextArea) {
console.log(rating);
console.log(myTextArea);
};
在我看来,我有:
<form name="reviewForm" class="form-horizontal" ng-submit="saveReview(rating, myTextArea)" novalidate>
<div>
<rating ng-model="rating" max="max" aria-labelledby="'product.title'"></rating>
</div>
<div>This is the rating: {{rating}}</div>
<div class="animate-switch" ng-switch-when=true>
<textarea ng-model="myTextArea" class="form-control" placeholder="Write a short review of the product." title="Review"></textarea>
</div>
<button type="submit" class="btn btn-primary pull-right">Submit Review</button>
</form>
当我提交表单时,将调用 saveReview 函数,控制台中的打印输出为 0 和 ''。因此,没有任何值被保存/传递。Ng-model 评分显示 5 星,如果您点击 4 星,{{rating}} 将显示 4。
有任何想法吗?