如何使用firebaseArray从ng-repeat获取子属性值?

时间:2016-06-24 21:01:26

标签: angularjs firebase

我想使用加载的firebaseArray从ng-repeat中获取所选值,检索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: 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)

1 个答案:

答案 0 :(得分:0)

ng-model应该在<select>标记中,而不在<option>