简体   繁体   English

如何在Ionic 3 Angular应用程序中对照数据库表检查有效的促销代码?

[英]How can I check for valid promo code in my Ionic 3 Angular app against the database table?

I am getting the data from the user in a new user registration screen. 我正在新的用户注册屏幕上从用户那里获取数据。 After clicking the register button, the data are getting saved in the database. 单击注册按钮后,数据将保存在数据库中。 I am using an input field called promocode, to check for the user's promo code. 我正在使用一个名为promocode的输入字段,以检查用户的促销代码。 Here's what I need: 这是我需要的:

I am having a set of promocodes already in a database table. 我在数据库表中已经有一组促销代码。 If the user types a promocode, and if the particular code exists in my database table, it can allow the user to register in my app. 如果用户键入促销代码,并且特定代码存在于我的数据库表中,则它可以允许用户在我的应用程序中注册。 Suppose if the user is typing a promocode that is not in my database table, it should display toast message as invalid promocode and so that the user is not allowed to register. 假设如果用户输入的促销代码不在我的数据库表中,则它应该将烤面包消息显示为无效的促销代码,从而不允许该用户注册。 This promocode validation should happened after the user fill all the details and after clicking the submit button. 此促销代码验证应在用户填写所有详细信息之后并单击“提交”按钮之后进行。

Here's what I have tried so far: 到目前为止,这是我尝试过的:

In my HTML: 在我的HTML中:

<ion-item>
<ion-icon name="ios-hand" class="iconstyle" item-left></ion-icon>

<ion-label color = "textcolor" floating>Reseller Promo Code</ion-label>
<ion-input type="text" class="textcolor" [(ngModel)] = "vm.promocode" formControlName = "promocode" maxlength = "15"  tabindex="2" (keyup)="moveFocus($event,query, false)" >
</ion-input>
</ion-item>

In my ts file: 在我的ts文件中:

import { Component } from '@angular/core';
import {IonicPage, NavController, NavParams } from 'ionic-angular';
import {SignupService} from '../../services/signup.service';
import { MessageService } from '../../services/message.service';
import { BroadCastService } from '../../services/broadcast.service';
import { isNullOrUndefined } from 'util';
import { Signup } from '../../models/signup';
import { FormGroup, FormControl, Validators, AbstractControl} from '@angular/forms';
import { LoginPage } from '../login/login';

@IonicPage()
@Component({
  selector: 'page-signup',
  templateUrl: 'signup.html',
  providers: [SignupService]
})
export class SignupPage{
formsignup: FormGroup;

submit(){


  if (this.formsignup.valid) {
    this.signupservice.savesignup(this.vm).subscribe(res=>{
      console.log(res);
      this.message.alert("Your account has been created successfully");
      this.resetForm(this.formsignup);
      this.navCtrl.push(LoginPage);
    });


  }
  else{
  this.validateFormControl(this.formsignup);
}
}

This is my service.ts file where I am posting the user details to the server and saving it in the database. 这是我的service.ts文件,我在其中将用户详细信息发布到服务器,并将其保存在数据库中。

import { Injectable } from "@angular/core";
import { DataService } from "./data.service";


@Injectable()
export class SignupService {
    constructor(private dataservice: DataService) {

    }

    savesignup(formdetails:any){
        return this.dataservice.post('/api/Login/Register', formdetails);
    }
}

In my model class I have used this promocode as follows: 在我的模型课程中,我使用了如下促销代码:

signup.ts: signup.ts:

export class Signup{
promocode: string;

Now everything is working fine. 现在一切正常。 All my data are saving in the database and I can able to login with the registered account. 我所有的数据都保存在数据库中,我可以使用注册的帐户登录。 But I don't know how to implement this functionality. 但我不知道如何实现此功能。 I am new to Ionic. 我是Ionic的新手。

You can (or "should") create your PromoService (Provider) and a method that should look something like this should work. 您可以(或“应该”)创建PromoService(提供者),以及应该看起来像这样的方法应该起作用。

public GetPromo(code: string): Promise<any> { //Can be strongly typed if you want to implement a class or interface for a Promo
    var url = '/GetPromo'; //your endpoint's url.
    var args: RequestOptionsArgs = {
        method: 'GET',
        params: {
            code : code //Your parameter. You can add more properties for multiple parameters.
        }
    };

    return this.http.request(url, args).map(res => res.json()).toPromise();
}

For post requests, parameters are attached to body . 对于发布请求,参数将附加到body

var args: RequestOptionsArgs = {
    method: 'POST',
    body: {
        code : code //Your parameter. You can add more properties for multiple parameters.
    }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何在Ionic 3 Angular应用程序中禁用按钮单击,直到取消祝酒消息? - How can I disable the button click in my Ionic 3 Angular app until the toast message gets dismissed? 如何在我的应用程序中使用Ionic 2 Pulling Refreher? - How can I use Ionic 2 Pulling Refresher in my app? 如何在ionic 3代码中解决此ngFor问题 - How can I solve this ngFor in my code for ionic 3 如何在 Cloud9 上预览我的 Ionic 应用程序? - How can I preview my Ionic App on Cloud9? Ionic2 Angular2:我似乎无法在我的应用程序中显示ng2图表 - Ionic2 Angular2: I can't seem to get an ng2-chart to appear in my app 我应该如何编写我的单次运行 RxJs 代码,以便我可以测试订阅泄漏? - How should I write my single run RxJs code so that I can test against subscription leaks? 如何使用Ionic4 / Angular在嵌套的Firestore数据库中检索所有用户的数据 - How do I retrieve the data of ALL of the users in my nested Firestore database using Ionic4/Angular 如何从我在 angular 的应用程序中检查调用方 url? - How can I check the caller url from my application in angular? 我如何将我的数据库与 Angular 应用程序连接起来 - How do i connect my database with Angular app 如何将我的 Angular 5 Web 应用程序部署到我的面板 - How can I deploy my Angular 5 web app to my panel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM