Javascript 接受意见书[Angularjs]
我正在与angularjs一起提交表格,但没有工作。任何人都可以发现我的错误: 我的表格:Javascript 接受意见书[Angularjs],javascript,angularjs,html,Javascript,Angularjs,Html,我正在与angularjs一起提交表格,但没有工作。任何人都可以发现我的错误: 我的表格: <form ng-controller="ReviewsController as reviewCtrl" ng-submit="reviewCtrl.addReview(product)"> <blockquote > <b>Stars: {{ reviewCtrl.review.stars }
<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>
我进入控制台时出现以下错误:
TypeError:无法读取未定义的属性“push”
在addReview()上
在fn处(评估时间(),:4:353)
在f()
以百万美元估价()
在m.$apply()
在HTMLFormElement。()
在HTMLFormElement.m.event.dispatch()处
在HTMLFormElement.r.handle()中,您正在将一个文本字符串(“gems”)传递给addReview方法,我从代码中看到,该方法需要一个名为“reviews”的数组属性的“product”对象。
product
是一个字符串。它没有评论
属性。应该是什么产品
呢?我不知道-这是你的应用程序。应该是具有reviews
属性的东西,该属性的值具有push
函数。我需要将新产品添加到gems
arrayvar gems=[{reviews:[{stars:5,body:“Great product”,作者:zamora@hotmail.rs" }, {明星:3,身体:“机器人坏”,作者:v@hotmail.rs“}]},{
。。。。
//Reviews
app.controller('ReviewsController' ,function(){
this.review = {};
this.addReview = function(product) {
product.reviews.push(this.review);
};
});