gpt4 book ai didi

javascript - 未捕获的类型错误 : Cannot read property 'element' of undefined when press login button

转载 作者:行者123 更新时间:2023-11-28 05:29:17 25 4
gpt4 key购买 nike

我收到此错误

Uncaught TypeError: Cannot read property 'element' of undefined

当我按下 ionic2 和 angular2 应用程序中的登录按钮时。我试图查看未初始化或未运行的变量,但我根本没有找到。

这就是登录功能

import { Component } from '@angular/core';
import { NavController,ViewController } from 'ionic-angular';
import { Storage} from '@ionic/storage';

//components
import { MyService } from '../../providers/my-service';
import { AdminPage } from '../admin/admin';

/*
Generated class for the ModalPage page.

See http://ionicframework.com/docs/v2/components/#navigation for more info on
Ionic pages and navigation.
*/
@Component({
selector: 'page-modal-page',
templateUrl: 'modal-page.html',
providers:[MyService]
})
export class ModalPage {

data:any;
public local: Storage;
private mydata:any;

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

}

login(){
let username = this.data.username;
let password = this.data.password;
let data = JSON.stringify({username, password});
this.service.postLogin(data)
.subscribe(data => {
this.mydata = data;
this.local.set('username', this.mydata[0].name);
this.local.set('token', this.mydata[0].token);
this.viewCtrl.dismiss();
}, error =>{
console.log(error);
})
}
dismiss(){
this.viewCtrl.dismiss();
}

}

这是我的服务页面

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

import { AdminPage } from '../pages/admin/admin';
/*
Generated class for the MyService provider.

See https://angular.io/docs/ts/latest/guide/dependency-injection.html
for more info on providers and Angular 2 DI.
*/
@Injectable()
export class MyService {

public local:Storage;
private mydata:any;
public getsession: any;
constructor(public http: Http,private local: Storage,private navCtrl:NavController) {
this.local=new Storage();

}
postLogin(data){
let link = "http://adirzoari.16mb.com/newapi.php";
return this.http.post(link,data)
.map(res => res.json())
}
checkToken(){
return this.getsession =this.local.get('token');

}
}

this is my error

when i press on the error-content-script.js

error shown

最佳答案

似乎您访问了“element模板中某处modal-page.html”字段。例如,

{{ something.element }}

如果是这样,请尝试使用 {{ some?.element }}

在访问字段之前检查某物是否存在(不为空或未定义)。

关于javascript - 未捕获的类型错误 : Cannot read property 'element' of undefined when press login button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39856720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com