【发布时间】:2015-06-18 02:54:26
【问题描述】:
我想用 angularjs 提交表单但没有工作任何人都可以找到我的错误在哪里:
我的表格:
<form ng-controller="ReviewsController as reviewCtrl" ng-submit="reviewCtrl.addReview(product)">
<blockquote >
<b>Stars: {{ reviewCtrl.review.stars }}</b>
{{ reviewCtrl.review.body }}
<cite>by: {{reciewsCtrl.review.author}}</cite>
</blockquote>
<select ng-model="reviewCtrl.review.stars">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input type="text" ng-model="reviewCtrl.review.body"/>
<input type="text" ng-model="reciewsCtrl.review.author"/>
<input type="submit"/>
</form>
app.js
//Reviews
app.controller('ReviewsController' ,function(){
this.review = {};
this.addReview = function(product) {
product.reviews.push(this.review);
};
});
我进入控制台的这个错误:
TypeError:无法读取未定义的属性“推送” 在 addReview (http://localhost/angular/js/app.js:107:25) 在 fn(评估在 (http://localhost/angular/js/angular.min.js:1:0), :4:353) 在 f (http://localhost/angular/js/angular.min.js:250:394) 在 m.$eval (http://localhost/angular/js/angular.min.js:134:83) 在 m.$apply (http://localhost/angular/js/angular.min.js:134:309) 在 HTMLFormElement。 (http://localhost/angular/js/angular.min.js:250:446) 在 HTMLFormElement.m.event.dispatch (https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js:3:8549) 在 HTMLFormElement.r.handle (https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js:3:5259)
【问题讨论】:
-
product是一个字符串。它没有reviews属性。 -
product应该是什么? -
我不知道 - 它是你的应用程序。它应该是具有
reviews属性的值具有push函数的东西。
标签: javascript angularjs html