Angular 角度-初始化并从DOM获取值

Angular 角度-初始化并从DOM获取值,angular,dom,Angular,Dom,在我的应用程序中,我有一个购物车组件,列出了所有项目。从一个产品链接到该组件 cart.component.html {{item['name']} 更新 {{item['price']}$ cart.component.ts 构造函数(私有configService:configService,私有url:ActivatedRoute){ this.url.queryParams.subscribe(params=>{ this.catId=params['catId']; this.pr

在我的应用程序中,我有一个购物车组件,列出了所有项目。从一个产品链接到该组件

cart.component.html


{{item['name']}
更新
{{item['price']}$
cart.component.ts

构造函数(私有configService:configService,私有url:ActivatedRoute){
this.url.queryParams.subscribe(params=>{
this.catId=params['catId'];
this.productId=params['productId'];
this.productPrice=params['productPrice'];
});
}
恩戈尼尼特(){
让item={“id”:this.productId,“price”:this.productPrice,“qty”:1};
此.configService.getCard(项).订阅(
(回应)=>{
this.productsList=响应;
this.total=this.productsList.pop();
}
);
}
updateQuantity(productId、productPrice、productQuantity){
let item={“id”:productId,“price”:productPrice,“qty”:productQuantity};
此.configService.getCard(项).订阅(
(回应)=>{
this.productsList=响应;
this.total=this.productsList.pop();
console.log(this.productsList);
}
);
}
getValue(){
让updateButton=document.getElementById(“数量”);
log(parseInt(updateButton.value));
返回parseInt(updateButton.value);
}
在初始化过程中,我将数量设置为1。但是当用户更新数量时,应该考虑新的值


但无论出于什么原因,即使我更新了数量,它仍然是1。我的
getElementById().value
似乎返回1而不是输入值。是不是因为我再次通过了
ngOnInit()

在模板中有一个for循环,其中设置了
id
,因此基本上有n个元素具有相同的id,这与
id
的概念相矛盾。关于值:使用angular不应该直接访问dom元素。此外,您应该使用
formGroups
formControls
并将它们绑定到您的输入。按照你目前的方法,你真的不需要角度。我明白了,那么我将使用表格。谢谢编辑:我使用ng模型进行两种方式的数据绑定,而且效果很好。谢谢