javascript - changing element in ngOnInit not working when changing route, but is able to access element
问题描述
I have an angular project with a router. In the ngOnInits for the components I want to dynamically set a a p tags value, and an img tags href. It works on inital load, but when i change routes the values dont change. The ngOnInit function is called, but the editing of the two elements does not work.
document.getElementById('discord-tag').innerHTML = username;
document.getElementById('profilePicture').setAttribute('src', image_url)
my code is simple.
i know the ngOnInit function is working because i put some console.log statements in there to test and they run each time i click on a route link.
解决方案
Try ngAfterViewInit() for changing 2 elements.
推荐阅读
- image - 更新 openshift 镜像
- javascript - 使用 d3.drag 拖动元素组时的跳跃行为
- arrays - 如何在c中创建数组的链表
- .net - 从下拉列表中选择的值在模型页面中为空
- r - R - 用于将列文本拆分为新列的 For 循环
- java - AWS 上 Flink 的空文件附加程序错误
- elasticsearch - 从 DBeaver 连接 Elasticsearch
- bootstrap-4 - 我在为我的网站修复标题中的间距时遇到问题(引导程序 4)
- python - 使用 Jupyter 笔记本无法从“tensorflow.python.compiler.tensorrt”导入名称“trt_convert”
- php - 无法解析的依赖解析[参数#1[
$var]] 类 App\View\Components\Header(View:laracurd\resources\views\welcome.blade.php)