Angular2 - ' [object Object]'模块' AppModule'

时间:2016-10-27 10:50:56

标签: angular firebase

我遇到将angularfire2集成到我的应用程序中的问题。我已经对大多数问题进行了排序,但我希望最后一个问题。我不确定错误是什么,但我已将其确定为以下代码。

这有效:

import UIKit
import CoreData

class TableViewController:  UIViewController,UITableViewDelegate,UITableViewDataSource {

@IBOutlet weak var tableView: UITableView!

var stores = [Store] ()

let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext

override func viewDidLoad() {
    super.viewDidLoad()

self.tableView.reloadData()

    // Do any additional setup after loading the view.
}

override func viewDidAppear(_ animated: Bool) {

    let request = NSFetchRequest <NSFetchRequestResult> (entityName: "Store")
    request.returnsObjectsAsFaults = false



    do {

        let results = try context.fetch(request) as! [Store]



        // check data existance
        if results.count>0 {
            print(results.count)

            for resultGot in results {

                if let expName = resultGot.name {
                    print("expence name is :", expName)

                    stores += [resultGot]

                    print("my array is : \(stores)")
                }
            }
            self.tableView.reloadData()
        }

    }catch{


        print("No Data to load")
    }


  }
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return stores.count
  }

   func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = UITableViewCell ()


    let store = stores [indexPath.row]
    cell.textLabel?.text = store.name

    //cell.textLabel?.text = myExpensesArray[indexPath.row]
    return cell
   }



  @IBAction func nextButtonPressed(_ sender: AnyObject) {

  }
 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    performSegue(withIdentifier: "editStore", sender: nil)

 }
 override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "editStore"{

        let v = segue.destination as! ViewController
        let indexPath = self.tableView.indexPathForSelectedRow
        let row = indexPath?.row
        v.store = stores[row!]


    }
 }

但这会在bootstrap属性中给出下面的错误:

//Other imports here
import { FIREBASE_PROVIDERS, defaultFirebase } from 'angularfire2';

@NgModule({
  imports: [
              BrowserModule,
              HttpModule,
              RouterModule.forRoot(routes),
              MainModule,
              SharedModule.forRoot()],

  declarations: [AppComponent],
  providers: [{
    provide: APP_BASE_HREF,
    useValue: '<%= APP_BASE %>'
  }],
  bootstrap: [AppComponent]

})

export class AppModule { }

1 个答案:

答案 0 :(得分:1)

它给你错误,因为你做错了方法,并且Bootstrap文件没有更新用于使用带有最新角度版本的模块。

Bootstrap文档中,第二个参数是我们的角度应用程序的提供者,所以在角度最新的realesed版本中,我们在@NgModule.providers内声明所有提供者,因此您必须执行以下操作:

//Other imports here
import { FIREBASE_PROVIDERS, defaultFirebase } from 'angularfire2';

@NgModule({
  imports: [
              BrowserModule,
              HttpModule,
              RouterModule.forRoot(routes),
              MainModule,
              SharedModule.forRoot()],

  declarations: [AppComponent],
  providers: [
    {
      provide: APP_BASE_HREF,
      useValue: '<%= APP_BASE %>'
    },
    FIREBASE_PROVIDERS,
    defaultFirebase({
      apiKey: 'keyhere',
      authDomain: 'key.firebaseapp.com',
      databaseURL: 'https://key.firebaseio.com',
      storageBucket: 'key.appspot.com'
    })
  ],
  bootstrap: [AppComponent]    
})

export class AppModule { }