Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 承诺离子/角度-用户连接_Angularjs_Ionic Framework_Ionic3_Angular Promise - Fatal编程技术网

Angularjs 承诺离子/角度-用户连接

Angularjs 承诺离子/角度-用户连接,angularjs,ionic-framework,ionic3,angular-promise,Angularjs,Ionic Framework,Ionic3,Angular Promise,我正在尝试使用promise来连接我的Ionic应用程序上的用户。 我尝试了很多东西。。。但这不起作用。有什么问题吗?你能帮我吗 在验证“访问”之前,我必须执行加载函数 这是我目前的代码。怎么了?(目前,错误是:“声明类型既不是'void'也不是'any'的函数必须返回值。”) 这是我的加载函数(没问题,这是我必须首先执行的) 这是我的登录功能: public login(credentials) : Observable<any>{ this.load(credenti

我正在尝试使用promise来连接我的Ionic应用程序上的用户。 我尝试了很多东西。。。但这不起作用。有什么问题吗?你能帮我吗

在验证“访问”之前,我必须执行加载函数

这是我目前的代码。怎么了?(目前,错误是:“声明类型既不是'void'也不是'any'的函数必须返回值。”)

这是我的加载函数(没问题,这是我必须首先执行的)

这是我的登录功能:

public login(credentials) : Observable<any>{
      this.load(credentials)
      .then( a =>
        {


          if (credentials.email === null || credentials.password === null) {
            return Observable.throw("Please insert credentials");
          } else {
            return Observable.create(observer => {
              // At this point make a request to your backend to make a real check!      


              let access = (credentials.password === "pass" && credentials.email === "email");
              this.currentUser = new User('Simon', 'saimon@devdactic.com');
              observer.next(access);
              observer.complete();


            });
          }
        }
        );
  }

不要字符串化选项,因为您必须以对象格式将数据发布到登录函数,如果字符串化选项,则表示您正在发布字符串。因此,您无法从credentials.email&credentials.password访问登录函数中的数据。请不要将选项字符串化,因为您必须以对象格式将数据发布到登录函数中,如果将选项字符串化,则表示您正在发布字符串。因此,您无法从credentials.email&credentials.password访问登录功能中的数据

是否检查登录抛出postmanare是否检查登录抛出postmanOk为什么不检查。但这并不能解决我的问题。我必须先执行一个方法,否则,我有一个“未定义的属性”(因为异步执行),http.post调用总是返回Observable,所以不要创建Observable.create这样。好主意。但是错误出现在我的第二个登录函数(最后一个代码)中。突出显示“订阅”。只有当我尝试使用承诺时,错误才会存在。事实上,如果我没有在我的提供者中使用“this.load(credentials).then(()=>…)”,我就不会有错误。好吧,为什么不呢。但这并不能解决我的问题。我必须先执行一个方法,否则,我有一个“未定义的属性”(因为异步执行),http.post调用总是返回Observable,所以不要创建Observable.create这样。好主意。但是错误出现在我的第二个登录函数(最后一个代码)中。突出显示“订阅”。只有当我尝试使用承诺时,错误才会存在。事实上,如果我没有在我的提供者中使用“this.load(credentials).then(()=>…)”,我就不会有错误。
public login(credentials) : Observable<any>{
      this.load(credentials)
      .then( a =>
        {


          if (credentials.email === null || credentials.password === null) {
            return Observable.throw("Please insert credentials");
          } else {
            return Observable.create(observer => {
              // At this point make a request to your backend to make a real check!      


              let access = (credentials.password === "pass" && credentials.email === "email");
              this.currentUser = new User('Simon', 'saimon@devdactic.com');
              observer.next(access);
              observer.complete();


            });
          }
        }
        );
  }
public login() {
    this.showLoading()
    this.auth.login(this.registerCredentials).subscribe(allowed => {
      if (allowed) {        
        this.nav.setRoot(HomePage);
      } else {
        this.showError("Access Denied");
      }
    },
      error => {
        this.showError(error);
      });
  }