I'm using AngularJS and I'm trying to create a template where I have an implicit object that calls test and inside test I have an array that I want to repeat when I call a function inside my Controller, but I'm getting undefined error when I'm trying do push an object inside the array.
Here is the example of my code:
<body ng-app="MyApp" ng-controller"MyController">
<input ng-model="person.name">
<button ng-click="createPhone()">
<div data-ng-repeat="phone in person.phones">
<input ng-model="phone.number">
</div>
</div>
</div>
Here is my Controller:
//app.controller...
$scope.createPhone(){
var phone = {number: '123456789'};
$scope.person.phones.push(phone);
}
I'm getting:
TypeError: Cannot set property 'phones' of undefined.
Could anyone help me?
$scope.aand$scope.b? I would post your whole controller so we can see what you are doing.