在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