add in firebase with angularfire $ add

1

My scripts:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular.min.js"></script><scriptsrc="https://cdn.firebase.com/libs/angularfire/2.2.0/angularfire.min.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.6.6/firebase.js"></script>

Hello,I'mabeginnerwithfirebaseandangular,Ihavethefollowingsituationinmybank:

Obs.valuesenteredmanually.

NowIwouldliketoleavedynamicwithangular,andIamdoingthefollowingcontrollerform:

app.controller("CtrlList", function($scope, $firebaseArray){

    var ref = firebase.database().ref().child("users");

    $scope.addUser = function(){
      $scope.users.$add({
        text: $scope.newUserText
      });
    };

And so my formulas:

<form ng-submit="addUser()">
  <input ng-model="newUserText" />
  <button type="submit">Add User</button>
</form>

As a beginner I'm a little lost and I can not save in firebase, I think I'm missing some concept.

    
asked by anonymous 18.01.2017 / 14:59

1 answer

1

I have registered the resolution of my problem, so the controller is as follows:

app.controller("CtrlList", function($scope, $firebaseArray){

    var ref = firebase.database().ref().child("users");

    data = $scope.users = $firebaseArray(ref);

    $scope.addUser = function(){          
      writeUserData($scope.newUserId, $scope.newUserName);          
    };

    function writeUserData(userId, name) {
      firebase.database().ref('users/' + userId).set({
        name: name
      });
    }

  });

And the form like this:

<form ng-submit="addUser()">
  <input ng-model="newUserId" placeholder="User" />
  <input ng-model="newUserName" placeholder="Name" />
  <button type="submit">Add User</button>
</form>
    
18.01.2017 / 15:50