angular2中的单向绑定不起作用
我发现如果我调试属性,它们会改变,但是UI不会更新。我做错了什么 下面是我用来测试它的代码:angular2中的单向绑定不起作用,angular,Angular,我发现如果我调试属性,它们会改变,但是UI不会更新。我做错了什么 下面是我用来测试它的代码: @Output() public currentProgressValue: number @Output() public currentProgressMaxValue: number @Output() public currentTaskName: string pushTask(maxValue: number, isIndeterminate: boolean = true, taskN
@Output() public currentProgressValue: number
@Output() public currentProgressMaxValue: number
@Output() public currentTaskName: string
pushTask(maxValue: number, isIndeterminate: boolean = true, taskName: string) {
var token = new ProgressToken(maxValue, isIndeterminate, taskName);
token.subscribe((x) => {
if (this.currentToken == null || this.currentToken == token) {
this.currentProgressValue = x;
this.currentProgressMaxValue = token.maxValue;
this.currentTaskName = token.taskName;
console.log(this.currentProgressValue)
}
if ((this.currentToken == token && x >= token.maxValue)) {
this.activeTasks = this.activeTasks.filter((x) => x != token);
var nextTask = this.activeTasks.find(x => x != null);
if (nextTask != null) {
this.isCurrentProgressIndeterminate = nextTask.isIndeterminate;
this.currentProgressMaxValue = token.maxValue;
this.currentProgressValue = x;
this.currentToken = nextTask;
}
}
});
this.activeTasks.push(token);
return token;
}
ProgressComponent用Injectable()标记,然后在构造函数中作为
import { ProgressComponent } from '../progress/progress.component'
@Component({
selector: 'login-component',
templateUrl: './login.component.html',
providers: [ProgressComponent]
})
参考这个答案:为什么所有这些变量都用@Output()注释?输出通常是一个rxjs主题,用于将数据从子对象传递到父对象。@JuliaPassynkova《绝望》的遗民试图修复它。我确实试过了,但没有发布更多的代码。首先尝试检查进度条是否与动态数据一起工作。i=0;setInterval(()=>{this.currentProgressValue=i++;this.currentProgressMaxValue=i++;},1000);它有效吗?@JuliaPassynkova老实说,我不认为有人会发布一个只处理静态数据的软件包,哈哈。无论如何,我可以看到数据在viewmodel中被更新,但它没有反映在UI中。
@Output() public currentProgressValue: number
@Output() public currentProgressMaxValue: number
@Output() public currentTaskName: string
pushTask(maxValue: number, isIndeterminate: boolean = true, taskName: string) {
var token = new ProgressToken(maxValue, isIndeterminate, taskName);
token.subscribe((x) => {
if (this.currentToken == null || this.currentToken == token) {
this.currentProgressValue = x;
this.currentProgressMaxValue = token.maxValue;
this.currentTaskName = token.taskName;
console.log(this.currentProgressValue)
}
if ((this.currentToken == token && x >= token.maxValue)) {
this.activeTasks = this.activeTasks.filter((x) => x != token);
var nextTask = this.activeTasks.find(x => x != null);
if (nextTask != null) {
this.isCurrentProgressIndeterminate = nextTask.isIndeterminate;
this.currentProgressMaxValue = token.maxValue;
this.currentProgressValue = x;
this.currentToken = nextTask;
}
}
});
this.activeTasks.push(token);
return token;
}
ngOnInit() {
if (isBrowser) {
this.progressToken = this.progress.pushTask(100, true, "Doing work");
var prog = 0;
let timer = TimerObservable.create(2000, 1000);
this.subscription = timer.subscribe(t => {
this.progressToken.next(this.v)
this.v = this.v + 1;
});
}
}
import { Subject } from 'rxjs/Subject'
import 'rxjs/Rx';
export class ProgressToken extends Subject<number> {
isIndeterminate: boolean
currentValue: number
maxValue: number
taskName: string
constructor(maximumValue: number, isIndeterminate: boolean, currentTaskName: string) {
super();
this.taskName = currentTaskName;
this.maxValue = maximumValue;
this.isIndeterminate = isIndeterminate;
}
}
import { ProgressComponent } from '../progress/progress.component'
@Component({
selector: 'login-component',
templateUrl: './login.component.html',
providers: [ProgressComponent]
})
private progress: ProgressComponent