Angular 在ngAfterInit中设置nativeElement.style.color不会';我不能在有角度的地方工作

Angular 在ngAfterInit中设置nativeElement.style.color不会';我不能在有角度的地方工作,angular,typescript,viewchild,Angular,Typescript,Viewchild,我正在学习,只是遇到了一个奇怪的问题。 当我将nativeElement.style.color设置为红色时,仅当我移除上面的img标记时,打印文本才会变为红色 似乎这是一个加载问题?但我使用ngAfterViewInit()将绘图涂成红色 希望有人能帮我:) import{Component,OnInit,Input,ViewChild,ElementRef,AfterViewInit}来自“@angular/core”; 从'@angular/router'导入{ActivatedRout

我正在学习,只是遇到了一个奇怪的问题。 当我将nativeElement.style.color设置为红色时,仅当我移除上面的img标记时,打印文本才会变为红色

似乎这是一个加载问题?但我使用ngAfterViewInit()将绘图涂成红色

希望有人能帮我:)

import{Component,OnInit,Input,ViewChild,ElementRef,AfterViewInit}来自“@angular/core”;
从'@angular/router'导入{ActivatedRoute};
从“../movie service”导入{MovieService};
从“../movie”导入{IMovie};
@组成部分({
选择器:“应用程序电影详细信息”,
templateUrl:'./movie detail.component.html',
样式URL:['./电影细节.component.scss']
})
导出类MovieDetailComponent实现OnInit,AfterViewInit{
@输入()电影:IMovie;
@ViewChild('plot',{static:false})plotRef:ElementRef;
ngAfterViewInit(){
this.plotRef.nativeElement.style.color=“红色”;
}
建造师(
专用路由:激活的路由,
私人电影服务:电影服务,
) { }
ngOnInit(){
这个.getMovie();
}
getMovie():void{
const id=this.route.snapshot.paramMap.get('id');
log(“id1:,id.toString”);
this.movieService.getMovie(id)
.订阅(电影=>{
这部电影=电影;
this.readmore(movie.Plot);
console.log(“movieDetail=”,movie);
console.log(“id1:,id”);
});
}
}

{{movie.Title}
类型:{{movie.Type}
年份:{{movie.Year}
分级:{{movie.Rated}
类型:{{电影.类型}
导演:{{movie.Director}}
演员:{{movie.Actors}
情节:{{movie.Plot}


由于您是在AfterViewInit Lifcycle中执行此操作,请使用ngOnInit钩子进行尝试。 以下是组件可用的生命周期挂钩

样式应该用CSS来完成