I asked this question before too. Maybe someone can caught the error here.
.controller('DishDetailController', ['$scope', function($scope) {
var dish={
name:'Uthapizza',
image: 'images/uthapizza.png',
category: 'mains',
label:'Hot',
price:'4.99',
description:'A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer.',
comments: [
{
rating:5,
comment:"Imagine all the eatables, living in conFusion!",
author:"John Lemon",
date:"2012-10-16T17:57:28.556094Z"
},
{
rating:2,
comment:"It's your birthday, we're gonna party!",
author:"25 Cent",
date:"2011-12-02T17:57:28.556094Z"
}
]
};
$scope.dish = dish;
}])
.controller('DishCommentController', ['$scope', function($scope) {
$scope.newcomment = {
rating : "",
comment: "",
author: "",
date: new Date().toISOString()
};
$scope.submitComment = function () {
$scope.newcomment.date = new Date().toISOString();
$scope.newcomment.rating = parseInt($scope.newcomment.rating)
console.log($scope.newcomment.comment);
console.log($scope.newcomment.author);
console.log($scope.newcomment.rating);
console.log($scope.newcomment.date);
$scope.dish.comments.push($scope.newcomment);
}
}]);
In html part part I have only two-three textbox. SubmitComment
in button onclick. Console.log show me the result which I need. But I cannot push this to array. The exercise is a part of tutorial. So it was requirement to write them in seperate controllers and this was provided by the tutorial