title: Post token device in webservice, using Nativescript
body: <p>Please can you share with me any idea, how to post in webservice and token device that generate from <code>onRegisterButtonTap(){}</code>.</p>
  
  <p>Like below you can see my code component. I want to add in this code and token device.</p>
  
  <pre><code>   register() {
      let newRegister = this.RegisterForm.value
      let user = new User(newRegister);
      this.registerservice.mobile_registergetdata(user).subscribe(
          result =&gt; {
              console.log(result)
              if (result === true) {
                  this.router.navigate(['/main']);
              } else {
                  this.areWeWaiting = false;
              }
          });
  }
  </code></pre>
  
  <p>Service Component :</p>
  
  <pre><code>  public mobile_registergetdata(user: User): Observable&lt;boolean&gt; {
  
      let headers = new Headers();
      headers.append('Content-Type', 'application/x-www-form-urlencoded');
      let body = user.generateUrlencodedParameters();
      return this.http.post(Api.getUrl(Api.URLS.mobile_registergetdata), body, {
        headers: headers
      })
        .pipe(map((response: Response) =&gt; {
          let res = response.json();
          console.log('res')
          console.log(res)
          if (res.StatusCode === 0) {
            this.router.navigate(['/']);
               return true;
           } else {
            return true;
          }
        }));
    }
  </code></pre>
  
  <p>And my User Class is like below:</p>
  
  <pre><code>export class User {
    username: string;
    password: string;
    token_device: string;
  
    constructor(obj?: any) {
      if (obj) {
        this.username= obj &amp;&amp; obj.username;
        this.password = obj &amp;&amp; obj.password;
        this.token_device= obj &amp;&amp; obj.token_device;
      }
    }
  
    public generateUrlencodedParameters(): string {
      let urlSearchParams = new URLSearchParams();
      urlSearchParams.append('username', this.username.toString());
      urlSearchParams.append('password', this.password.toString());
      urlSearchParams.append('token_device', this.token_device.toString());
  
      return urlSearchParams.toString();
    }}
  </code></pre>
  
  <p>Like below you can see my code Component.</p>
  
  <pre><code> export class RegisterComponent implements OnInit {
      RegisterForm: FormGroup;
      loading: boolean = false;
      areWeWaiting = false;
      invalidInputs: boolean = false;
      constructor(private formBuilder: FormBuilder, private registerservice: RegisterUserService, private router: Router, private routerExtensions: RouterExtensions) {
          this.RegisterForm = this.formBuilder.group({
              username: ["", Validators.required],
              password: ["", Validators.required]
          });
      }
         register() {
          let newRegister = this.RegisterForm.value
          let user = new User(newRegister);
          this.registerservice.mobile_registergetdata(user).subscribe(
              result =&gt; {
                  console.log(result)
                  if (result === true) {
                      this.router.navigate(['/main']);
                  } else {
                      this.areWeWaiting = false;
                  }
              });
      }
      public goBack() {
          this.routerExtensions.backToPreviousPage();
      }
  
      private pushSettings = {
          // Android settings
          senderID: "610353931028", // Android: Required setting with the sender/project number
          notificationCallbackAndroid: (stringifiedData: String, fcmNotification: any) =&gt; {
              const notificationBody = fcmNotification &amp;&amp; fcmNotification.getBody();
              console.log(notificationBody)
              this.updateMessage("Message received!\n" + notificationBody + "\n" + stringifiedData);
          },
      };
      private _message: string;
      get message(): string {
          return this._message;
      }
      set message(value: string) {
          if (this._message !== value) {
              this._message = value;
              //this.notifyPropertyChange("message", value);
          }
      }
  
      onCheckButtonTap() {
          let self = this;
          pushPlugin.areNotificationsEnabled((areEnabled: Boolean) =&gt; {
              self.updateMessage("Are Notifications enabled: " + !!areEnabled);
          });
      }
  
      onRegisterButtonTap() {
          let self = this;
          pushPlugin.register(this.pushSettings, (token: String) =&gt; {
              self.updateMessage("Device registered. Access token: " + token);
              console.log('"Device registered. Access token: " + token')
              console.log("Device registered. Access token: " + token)
              if (pushPlugin.registerUserNotificationSettings) {
                  pushPlugin.registerUserNotificationSettings(() =&gt; {
                      self.updateMessage("Successfully registered for interactive push.");
                  }, (err) =&gt; {
                      self.updateMessage("Error registering for interactive push: " + JSON.stringify(err));
  
                  });
              }
          }, (errorMessage: String) =&gt; {
              self.updateMessage(JSON.stringify(errorMessage));
          });
      }
  
      private updateMessage(text: String) {
          this.message += text + "\n";
      }
  }
  </code></pre>
  
  <p>Any idea please?</p>
  
  <p>Thank you so much.</p>