2016-07-28 43 views
2

通過使用普通的JavaScript,我可以使用火力存儲像下面在AngularFire中,我們如何獲得像普通JavaScript那樣的存儲引用?

var config = { 
    apiKey: "AIzaSyCJ3RdrcdO_Zph5DKPN-RLmJsR5fBD7S5w", 
    authDomain: "myapp-90faa.firebaseapp.com", 
    databaseURL: "https://myapp-90faa.firebaseio.com", 
    storageBucket: "myapp-90faa.appspot.com", 
}; 

firebase.initializeApp(config); 

// file from some event e 
var file = e.target.files[0]; 
var storage = firebase.storage().ref('images/'+file.name); 
var task = storage.put(file); 

但如何代碼才達到在角火存儲對象?在這裏我只是指一個數據庫:

var myApp = angular.module('myApp', ['firebase']); 
var myProducts = new Firebase('https://myapp-90faa.firebaseio.com/products'); 

myApp.controller('ProductsCtrl', ['$scope', '$firebaseArray', function($scope,$firebaseArray) { 
+0

Firebase存儲尚未包裝在AngularFire 2.x中。看到這個[Github問題跟蹤其進展](https://github.com/firebase/angularfire/issues/785)。 –

回答

0

對於AngularJS,因爲2.3版本已經有可能的Angularfire

app.controller("MyCtrl", ["$scope", "$firebaseStorage", 
    function($scope, $firebaseStorage) { 
     var storageRef = firebase.storage().ref("images/dog"); 
     $scope.storage = $firebaseStorage(storageRef); 
    } 
]); 

對於超出1.x版本角,AngularFire2也有火力的API存儲:

constructor(private fb: FirebaseApp) { 
    const storageRef = fb.storage().ref("images/dog") 
} 
相關問題