I'm trying to create a member's form with all the pre-defined phone types.
I'm making two api requests for member and phone types. Here is what I've:
First request with member's information:
$scope.member = {
// $scope.member is returned from an api call
"name": "John Doe",
"phones": [{
"id": "Cell",
"phone": "(651) 111-1899",
"phone_unlisted": false
}, {
"id": "Work",
"phone": "(555) 121-1212",
"phone_unlisted": true
}]
};
Second request to get phone types:
myApp.controller("phoneTypes", function ($scope) {
// $scope.phoneTypes is returned from an api call
$scope.phoneNames = [{
"id": "Cell"
}, {
"id": "Cell 2"
}, {
"id": "Work"
}, {
"id": "Work 2"
}];
});
An unsuccessful attempt to create this form.
HTML -
<div ng-controller="memberInfo">
<h3>{{member.name}}</h3>
<form role="form" ng-controller="phoneTypes">
<h4>Phones</h4>
<div ng-repeat="phoneName in phoneNames" >
<label>{{phoneName.id}}</label>
//need to bind phone detail from $scope.member if exists otherwise leave blank
<input type="text" ng-model="member.phones.phone" />
unlisted: <input type="checkbox" ng-model="member.phones.phone_unlisted" />
</div>
</form>
</div>
I need to bind phone number of each matched phone types, otherwise leave the input field blank.
Here is http://jsfiddle.net/4nzg4/
I've gone through various tutorials and posts but I'm not able to solve this. I'm new to AngularJS, any help will be appreciated.
Thank you,