2017-09-13 71 views
0

試圖從https://dart.academy/build-a-real-time-chat-web-app-with-dart-angular-2-and-firebase-3/學習,但在實施在角填充火力地堡數據庫的名單達特

  • 錯誤-1

    同時調試GET http://localhost:56991/main.dart 404 (Not Found)

  • 錯誤-2

    enter image description here

firebase_service.dart

import 'package:angular/angular.dart'; 
import 'package:firebase/firebase.dart' as fb; 
import 'package:yns_admin/category_component/category.dart'; 

@Injectable() 
class FirebaseService { 

    fb.Database fbDatabase; 
    fb.DatabaseReference databaseReference; 

    List<Category> categories; 

    FirebaseService() { 
    fb.initializeApp(
     apiKey: "AIzaSyBOShlCgUeqTL99n32ssasasasasa", 
     authDomain: "yns-app.firebaseapp.com", 
     databaseURL: "https://yns-app.firebaseio.com", 
     storageBucket: "yns-app.appspot.com", 
    ); 

    fbDatabase = fb.database(); 
    databaseReference = fbDatabase.ref("categories"); 
    } 

    void showCategories() { 
    categories = []; 
    databaseReference.onChildAdded.listen(newCategory); 
    } 

    void newCategory(fb.QueryEvent event) { 

    Category category = new Category.fromMap(event.snapshot.val()); 
    categories.add(category); 
    } 
} 

地圖代碼來自 category.dart

class Category { 

    final String categoryTitle; 

    Category(this.categoryTitle); 

    Category.fromMap(Map map, this.categoryTitle) {} 

    Map toMap() =>{ 
    "categoryTitle":categoryTitle 
    }; 
} 

main.dart

import 'package:angular/angular.dart'; 
import 'package:yns_admin/app_component/app_component.dart'; 

void main() { 
    bootstrap(AppComponent); 
} 
+0

'fromMap()'從哪裏來?你在使用'json_serializable'包嗎? –

+0

我已經添加了category.dart的地圖代碼 –

+1

您的'fromMap(...)'需要2個值,但您只傳遞一個'event.snapshot.val()'。你的'fromMap(...)'似乎對預期的'Map'參數沒有任何作用。 –

回答

0

Q1:http://localhost:56991/main.dart應該是404,這是預期的行爲。如果你只是訪問http://localhost:56991,你應該看到你的組件。欲瞭解更多信息,請查看Angular Dart official doc。第二季度:我認爲你需要修改你的new Category.fromMap()函數來檢查快照值。不確定你會怎麼做,但它應該相當容易。