在Aurelia中可以使用具有自定义属性的vanilla js setAttribute()
吗?当我检查dom时,更改是在自定义元素上进行的,但无论我尝试什么,它都不会在我的模型或视图中触发任何内容。有没有一种“最佳实践”的方式来做到这一点?在Aurelia自定义属性上使用setAttribute()
home.ts
export class Home{
public onButtonClicked():void{
document.getElementById('test123').setAttribute('color', 'green');
}
}
home.html的
<template>
<require from="../../elements/now-loading-circle/now-loading-circle"></require>
<button click.delegate="onButtonClicked()">Click</button>
<now-loading-circle id="test123" color="red"></now-loading-circle>
</template>
现在加载-circle.ts
import {bindable, autoinject} from 'aurelia-framework';
@autoinject
export class NowLoadingCircle{
@bindable color:string;
public colorChanged(newValue):void{
alert(newValue);
}
}
现在加载-circle.html
<template>
<svg viewBox="0 0 120 120">
<circle repeat.for="circ of coords" cx="${circ.x}" cy="${circ.y}" r="${smallCircleRadius}" class="circ-${$index + 1}"></circle>
</svg>
</template>
你尝试使用的setAttribute()?它怎么样? – zynkn
@YoungKyunJin是的,当我检查dom时,更改是在自定义元素上进行的,但无论我尝试什么,它都不会在我的模型或视图中触发任何内容。 –
我可以看到你的代码吗? – zynkn