如何使用knockout js在寄存器组件中调用html

时间:2015-03-17 06:44:35

标签: knockout.js

我刚刚研究过淘汰赛。我想创建像angularJs指令一样的指令。但是我不能在寄存器组件中调用html页面。

如果有人知道,请帮助我。非常感谢。

我的html页面是myComponent.html

<div><h4>Hello Word</h4></div>

我的js文件是myComponent.js

ko.components.register('my-component',{
  templeate: /I want call my html page/,
  viewModel: function(){
  }
});
ko.applyBindings();

2 个答案:

答案 0 :(得分:1)

您的样本中似乎有拼写错误的模板。不确定这是否相关。

答案 1 :(得分:0)

您可以使用任何AMD加载程序,例如require JS,

ko.components.register('my-component', {
    viewModel: { require: 'files/my-component' },
    template: { require: 'text!files/my-component.html' }
});

请阅读有关JS的信息,请点击此链接http://requirejs.org/