I'm using bootstrap 4 with Angular 2 and have the following select:
<div class="form-group">
<label for="isActived" class="col-sm-4 control-label">Add BY</label>
<div class="col-sm-16">
<ng-container *ngFor="let user of users">
<select class="custom-select" *ngIf="user.name == test" name="State" required
[(ngModel)]="model.isActived" #isActived="ngModel">
<option selected value="0">{{test}}</option>
</select>
</ng-container>
</div>
</div>
My first question is when i use this selected i can't get it as default
my second one is how i can convert the value of test to integer i get this error: "message": "SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: i use the parseInt() and many solution but i still have the same error
getAllUsers() {
this.userService
.showAllUsers()
.subscribe(users => {
this.users = users;
let userData = localStorage.getItem('currentUser');
if (!userData) return null;
let userrData = JSON.parse(userData);
var jwt = require('jsonwebtoken');
const tokenPayload = decode(userrData.token, {complete: true});
for (let user of users) {
if (tokenPayload.sub == user.id) {
parseInt(this.test = user.name);
}
}
});
}
so can i get some help
user.nameis astringbut you want it to be anumber, you can use the syntaxthis.test = +user.nameto convert it to anumber. If you want to useparseInt(..), you need to swap your code tothis.test = parseInt(user.name, 10)user.nameis not a number. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…user.nameis the property that you want to convert to a number?