I am stuck AngularJS and JSON. I have view called form.html that allow user can select their province. I created Province JSON file and put in select tag, but when I store mySQL I need a province Id I tried ng-value="province.id" in option tag but doesn't work. How can I get a pid(provinceId) at same time when user select province?
province.JSON
[
{
"pid" : 1,
"name" : "Ontario"
},
{
"pid" : 2,
"name" : "Québec"
},
{
"pid" : 3,
"name" : "Nova Scotia"
},
{
"pid" : 4,
"name" : "New Brunswick"
},
...
form.html
<select name="province" ng-model="user.province" ng-required="true">
<option value="">--- Please select ---</option>
<option ng-repeat="province in provinces">{{province.name}}</option>
</select>
controllers.js
$scope.submitForm = function (user) {
dataObj = {
"name": user.name, //it works and all fine
"province": user.province, //it works and all fine
"telephone": user.telephone, //it works and all fine
"postalcode": user.postalcode, //it works and all fine
"salary": user.salary, //it works and all fine
"provinceId" : user.pid // undefine ..
}
<option ng-repeat="province in provinces" ng-value="province.pid">{{province.name}}</option>?ng-optionsinsteadng-repeat.