Gabriel Fabri Gabriel Fabri - 5 months ago 26
AngularJS Question

How to get sub property value from ng-repeat using a firebaseArray?

I want to get the selected value from ng-repeat using the firebaseArray loaded, retrieving the value of profile.name

.json

profile: {
name: 'default',
description: 'default',
permissions: {
regUser: false,
regProfile: false,
regCustomer: false
}
}


.html

<select class="form-control">
<option ng-repeat="profile in vm.profiles" ng-model="vm.firebaseUser.profile">{{profile.name}}</option>
</select>


.js

vm.createApplicationUser = function() {
var profilesRef = firebase.database().ref('application/profiles/name/');
vm.profiles = $firebaseArray(profilesRef);
var usersRef = firebase.database().ref('application/users/').push().set({
displayName: vm.firebaseUser.displayName,
email: vm.firebaseUser.email,
role: vm.firebaseUser.role,
profile: vm.firebaseUser.profile
});
};


error

Error: Firebase.set failed: First argument contains undefined in property 'application.users.-KL3BQ-F5a-HLa32an-R.profile'
at Error (native)
at Bf (http://localhost:3000/bower_components/firebase/firebase.js:340:67)
at http://localhost:3000/bower_components/firebase/firebase.js:341:166
at Cb (http://localhost:3000/bower_components/firebase/firebase.js:259:627)
at Bf (http://localhost:3000/bower_components/firebase/firebase.js:340:424)
at Af (http://localhost:3000/bower_components/firebase/firebase.js:339:682)
at U.g.set (http://localhost:3000/bower_components/firebase/firebase.js:467:241)
at AdminCtrl.vm.createApplicationUser (http://localhost:3000/src/client/app/admin/admin.js:28:81)
at fn (eval at <anonymous> (http://localhost:3000/bower_components/angular/angular.js:14605:15), <anonymous>:4:271)
at expensiveCheckFn (http://localhost:3000/bower_components/angular/angular.js:15694:18)

Answer

The ng-model should be in <select> tag and not in <option>.

Comments