未捕获的错误:无法解析MyloginPage的所有参数

时间:2018-07-09 11:24:51

标签: html ionic-framework ionic3

我创建了一个登录页面,当我从php api传递数据时,我想将该数据存储到localStorage,但是每当我单击登录页面的按钮时,总是会发生错误。

基于此错误,我已经在网上搜索了更多详细信息,但我什么都没想。

以下是我尝试访问登录页面时显示在屏幕上的错误:

ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[MyloginPage -> AuthServiceProvider]: 
  StaticInjectorError(Platform: core)[MyloginPage -> AuthServiceProvider]: 
    NullInjectorError: No provider for AuthServiceProvider!
Error: StaticInjectorError(AppModule)[MyloginPage -> AuthServiceProvider]: 

下面是图像:

enter image description here

Mylogin.html

 <ion-content padding>
    <ion-list>
    <ion-item>
      <ion-label>username</ion-label>
      <ion-input type="text" name="username" [(ngModel)]="data.username"></ion-input>
    </ion-item>

    <ion-item>
      <ion-label>password</ion-label>
      <ion-input type="password" name="password" [(ngModel)]="data.password"></ion-input>
    </ion-item>

  </ion-list>
   <button ion-button color="primary" full (click)="login()">Login</button>

  </ion-content>


**mylogin.ts**

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ViewController  } from 'ionic-angular';
import { AuthServiceProvider } from '../../providers/auth-service/auth-service';
import { Storage } from '@ionic/storage';


/**
 * Generated class for the MyloginPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-mylogin',
  templateUrl: 'mylogin.html',
})
export class MyloginPage {
  data: any;
  public local : Storage;

  constructor(public navCtrl: NavController, public navParams: NavParams, private viewCtrl: ViewController, private service: AuthServiceProvider) {
    this.data = {};
    this.data.username = "";
    this.data.password = "";
    this.local = new Storage(null);

  }



  ionViewDidLoad() {
    console.log('ionViewDidLoad MyloginPage');
  }

  login() {
    let username = this.data.username;
    let password = this.data.password;
    let data = JSON.stringify({username, password});
    this.service.postLogin(data);


  }
  dismiss(){
    this.viewCtrl.dismiss();
  }

}

Auth-service.ts

//import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import { Storage } from '@ionic/storage';

/*
  Generated class for the AuthServiceProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class AuthServiceProvider {
  public local : Storage;
  mydata: any;

  constructor( public http: Http) {
    this.local = new Storage(null)
  }

  postLogin(data){
    let link = "http://textkhmer.com/api/securelogin.php";
      return this.http.post(link, data)
        .map(data => {
          this.mydata = data;
          console.log("data")
        }, error =>{
          console.log(error)
        })
  }



}

请为什么显示此错误?

谢谢

0 个答案:

没有答案