javascript - Nested objects and ng-models in Angular-JS - Stack Overflow

I am looking for solution for a problem which might not exist the way I am trying to do it. So if anyon

I am looking for solution for a problem which might not exist the way I am trying to do it. So if anyone can help me with the best way of doing this.

ISSUE:

I have the following input field:

 <input type="text" placeholder="quote" ng-model="person.quotes.quote">
 <input type="text" placeholder="author" ng-model="person.author">
 <input type="text" placeholder="category" ng-model="person.category">

And I have the following object:

$scope.person = {
author: $scope.author,
category: $scope.category,
quotes: [{quote: $scope.quote}]
};

I am trying to get the value person.quote into the array of quotes. But I can't seem to do it.

REASON:

The reason why I am doing this is that when a user fills the input fields and clicks on a button the values are saved into the $scope.person object. And that I push that entire object to my firebase API. I want to maintain the structure of my $scope.person object as I have described in my javascript the same in my firebase API. I can easily push author and category but the nested quotes objects are not being pushed.

THE ERROR I GET:

Error: Firebase.set failed: First argument contains undefined in property 'quotes.0.quote'

Thanks in advance and if this information is not enough please let me know so i can provide with more information.

I am looking for solution for a problem which might not exist the way I am trying to do it. So if anyone can help me with the best way of doing this.

ISSUE:

I have the following input field:

 <input type="text" placeholder="quote" ng-model="person.quotes.quote">
 <input type="text" placeholder="author" ng-model="person.author">
 <input type="text" placeholder="category" ng-model="person.category">

And I have the following object:

$scope.person = {
author: $scope.author,
category: $scope.category,
quotes: [{quote: $scope.quote}]
};

I am trying to get the value person.quote into the array of quotes. But I can't seem to do it.

REASON:

The reason why I am doing this is that when a user fills the input fields and clicks on a button the values are saved into the $scope.person object. And that I push that entire object to my firebase API. I want to maintain the structure of my $scope.person object as I have described in my javascript the same in my firebase API. I can easily push author and category but the nested quotes objects are not being pushed.

THE ERROR I GET:

Error: Firebase.set failed: First argument contains undefined in property 'quotes.0.quote'

Thanks in advance and if this information is not enough please let me know so i can provide with more information.

Share Improve this question asked Nov 27, 2014 at 21:43 SkywalkerSkywalker 5,20417 gold badges66 silver badges127 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

the property quotes from object person is array.

ng-model="person.quotes[0].quote"

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745459714a4628650.html

相关推荐

  • javascript - Nested objects and ng-models in Angular-JS - Stack Overflow

    I am looking for solution for a problem which might not exist the way I am trying to do it. So if anyon

    9小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信