2015-11-05 19 views
1

我正在玩Onsen用户界面,并想知道是否有一种方法来定义和包括HTML的片段,而不使用Angular JS时使用Onsen UI?温泉用户界面 - 不使用Angular JS的可重用HTML片段?

例如,说我有两个页面:

<ons-template id="page1.html"> 
    <ons-page> 
     <ons-toolbar> 
      <ons-toolbar-button onclick="menu.toggleMenu()"><ons-icon icon="fa-bars"></ons-icon></ons-toolbar-button> 
      <div class="center">Page 1</div> 
     </ons-toolbar> 
     <p>Page 1 content</p> 
    </ons-page> 
</ons-template> 

<ons-template id="page2.html"> 
    <ons-page> 
     <ons-toolbar> 
      <ons-toolbar-button onclick="menu.toggleMenu()"><ons-icon icon="fa-bars"></ons-icon></ons-toolbar-button> 
      <div class="center">Page 2</div> 
     </ons-toolbar> 
     <p>Page 2 content</p> 
    </ons-page> 
</ons-template> 

<ons-toolbar-button>的定义被复制在两个页面,那么有没有一种机制来定义的代码片段,并注入其多次?

<ons-toolbar-button onclick="menu.toggleMenu()"><ons-icon icon="fa-bars"></ons-icon></ons-toolbar-button> 

我知道,采用了棱角分明这个功能可以使用ngInclude指令来完成,但如果<ons-template>想能以某种方式来做到这一点,而不需要去角?

回答

1

Onsen UI 1.x基于Angular,因此很难不使用任何操作。

你在找什么是基于Web组件的Onsen UI 2。这意味着它是完全不可知的(独立于平台),可以与任何其他框架结合使用。实际上它是在alpha版本中发布的,但它已经非常稳定,很快就会有beta版本。

如果你想看看温泉UI 2.0,您可以:

Quickstart 
$ git clone http://github.com/OnsenUI/onsenui2-quickstart 
$ cd onsenui2-quickstart 
$ npm install && gulp serve 
+0

我会来了同样的结论,虽然温泉UI 1.x中声称没有角的工作,这是很难使用它没有。 v2.0看起来很有希望 - 谢谢指出。 – DaveAlden

+0

Onsen UI 1.x在[官方网站](https://onsen.io)中声称无Angular工作:'与jQuery和AngularJS兼容' –

+0

好的,我应该让自己更清楚:)我的意思是Onsen UI 1.x声明可以在不需要使用AngularJS构造的情况下使用(也就是说,你可以使用jQuery来代替),但事实上,因为它建立在Angular上,所以在某些时候你会被卡住,除非你使用AngularJS eg需要ngInclude来包含HTML片段。 – DaveAlden

相关问题