2017-09-13 70 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()函数来检查快照值。不确定你会怎么做,但它应该相当容易。