How to set 'href' on a link in KnockoutJS?

2

I'm starting with KnockoutJS and would like to know if it has a way to attach a link received by AJAX / JSON to a <a href="meu link aqui">Meu link</a> tag.

HTML:

<div data-bind="text: url"></div>

<hr/>

<a data-bind="href: url">Google</a>

Javascript:

function App() {
  this.url = "http://www.google.com.br/";
}

ko.applyBindings( new App() );

In JSFiddle: link

    
asked by anonymous 15.07.2014 / 16:12

1 answer

2

Just use the attr binding

<a data-bind="attr: { href: url }">
    Report
</a>

<script type="text/javascript">
    var viewModel = {
        url: ko.observable("http://www.google.com.br/"),
    };
</script>

source: link

    
15.07.2014 / 16:20