Javascript in template can't working?

Hi all, I have no idea why the script tag can’t working, here is the reproduce step:
ionic cli 1.3.10
1.ionic start mytab
2.add following to templates/chat-detail.htm in ion-content

<p id="demo"></p>

document.getElementById("demo").innerHTML = txt.length;

3.ionic serve --lab
4.navigate to chat detail page,the script couldn’t work

why is that happened?