2017-07-08 2 views
0

Ich versuche eine Firebase + Angularfire-Anwendung zu erstellen, jedoch kann ich angularfire wegen dieses Fehlers nicht verwenden. Ich kann eine Verbindung zu Firebase herstellen und eckig ohne Verwendung von angularfire laden.

ReferenceError: $firebaseObject is not defined Stack trace: @http://localhost:5000/scripts/controllers.js:5:13 [email protected]http://localhost:5000/components/angular/angular.js:5003:16 [email protected]http://localhost:5000/components/angular/angular.js:10866:24 [email protected]http://localhost:5000/components/angular/angular.js:9746:35 [email protected]http://localhost:5000/components/angular/angular.js:9055:13 [email protected]http://localhost:5000/components/angular/angular.js:9058:13 [email protected]http://localhost:5000/components/angular/angular.js:9058:13 [email protected]http://localhost:5000/components/angular/angular.js:8920:30 bootstrapApply/<@http://localhost:5000/components/angular/angular.js:1919:11 [email protected]http://localhost:5000/components/angular/angular.js:18161:16 [email protected]http://localhost:5000/components/angular/angular.js:18261:20 [email protected]http://localhost:5000/components/angular/angular.js:1917:9 [email protected]http://localhost:5000/components/angular/angular.js:5003:16 doB[email protected]http://localhost:5000/components/angular/angular.js:1915:5 [email protected]http://localhost:5000/components/angular/angular.js:1935:12 [email protected]http://localhost:5000/components/angular/angular.js:1820:5 @http://localhost:5000/components/angular/angular.js:33367:5 [email protected]http://localhost:5000/components/angular/angular.js:3431:5

controllers.js

angular.module('ghfzero',['firebase']) 

.controller('testController', ['$scope',function($scope) { 
     var ref = firebase.database().ref(); 
     var obj = $firebaseObject(ref); 

     ref.set({ 
      first:"hello", 
      last:"world" 
     }); 

}]) 

index.html

<!DOCTYPE html> 
<html lang="en" ng-app="ghfzero"> 

<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <title>Welcome to Firebase Hosting</title> 
</head> 

<body> 

    <h1>firebase working ok with angular prelims</h1> 
    <form ng-controller="testController"> 
     <input type="text" name="test" ng-model="angtest"> 
     <input type="submit" value="add test"> 
     <h2>{{angtest}}</h2> 
     <button ng-click="addMessage()">test db</button> 
    </form> 

    <script src="https://www.gstatic.com/firebasejs/4.1.3/firebase.js"></script> 
    <script> 
     // Initialize Firebase 
     var config = ...... 
      ......... 
     firebase.initializeApp(config); 
    </script> 
    <!--Firebase 3.0.0 and above require angularfire ver ^2.3.0!--> 
    <!--Initializing Angular, Angular Ui Router, Angular Fire, jQuery!--> 
    <script src="components/angular/angular.js"></script> 
    <script src="components/angular-ui-router/release/angular-ui-router.js"></script> 
    <script src="components/angularfire/dist/angularfire.js"></script> 
    <script src="components/jquery/dist/jquery.js"></script> 
    <script src="scripts/controllers.js"></script> 

</body> 

</html> 
+2

Sie müssen $ firebaseObject in Ihren Controller injizieren wie .controller ('testController', ['$ scope', '$ firebaseObject'function ($ scope, $ firebaseObject) – Vivz

Antwort

1

inject de $ firebaseObject in der Steuerung wie folgt aus:

... .Controller ('Testcontroller' , Funktion ($ scope, $ firebaseObject) { ...