我正在将html内容附加到服务的正文中。 (非常需要)
这是我的服务
import { Injectable, OnInit } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class AppConfig {
option:string;
popup = `<div class="main-section">
<div class="singin-options">
<div class="form-check form-check-inline">
<input class="form-check-input" (change)="onLoginChange($event)" value="CTS" type="radio" name="loginOption" id="inlineRadio1">
<label class="form-check-label" for="inlineRadio1">Login as ABC Member</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" (change)="onLoginChange($event)" value="IBO" type="radio" name="loginOption" id="inlineRadio2">
<label class="form-check-label" for="inlineRadio2">Login as XYZ Member</label>
</div>
</div>
<div class="signin">
<button type="button" class="btn btn-success">Sign In</button>
</div>
</div>`
constructor(private store:Store<StateShared>){}
initializeData() {
return new Promise((resolve, reject) => {
$('body').append(this.popup);//appended
return setTimeout(() => {
resolve(true) //get value from user, wait until
}, 5000)
});
}
onLoginChange(){ console.log('loo')}
}
答案 0 :(得分:0)
我通过将所有事件添加到promise之内来解决了这个问题,
return new Promise((resolve, reject) => {
if(!localStorage.getItem("name")){
$('body').append(this.popup);
$("input[name=loginOption]:radio").change(function (event) {
that.userOption = $(event.target).val();
$("button").prop('disabled', false);
})
$("button").prop('disabled', true);
$("button").click(function () {
that.value = false;
localStorage.setItem("name", that.userOption);
resolve(true);
})
}
if(localStorage.getItem("name")){
resolve(true);
}
});
对我来说很好。