简体   繁体   English

AngularJS bootstrap-ui标签拉入本地html内容

[英]AngularJS bootstrap-ui tabs pulling in local html content

I have set up a simple application and I want to pull in, for now, a local html file as the content of each tab. 我已经设置了一个简单的应用程序,我想暂时将本地html文件作为每个选项卡的内容。 I also only want the 'apple' content to be displayed under the 'Apple' tab and the same for pear keeping my html as simple as possible as in the future more fruits could be added. 我也只想在'Apple'选项卡下显示'apple'内容,并且对于pear保持我的html尽可能简单,因为将来可以添加更多的水果。

Please see the plunker for my current configuration: http://plnkr.co/edit/Y6Ey8vbvrq3xzvBhJS7o?p=preview 请参阅我的当前配置的plunker: http ://plnkr.co/edit/Y6Ey8vbvrq3xzvBhJS7o?p = preview

  <tab ng-repeat="tab in tabs" heading="{{tab.title}}" select="getContent($index)" active="tab.active" disabled="tab.disabled">
  <div ng-hide="!tabs.isLoaded">
  <h1>{{tab.title}}</h1>
    <div ng-repeat="item in tabs.content">
      <p>{{item[tab.title]}}</p>
    </div>
  </div>
  <div ng-hide="tabs.isLoaded"><h3>Loading...</h3></div>
  </tab>

My question is, can you help me identify how to only pull in the specific content for each tab that is part of one html file? 我的问题是,您能否帮我确定如何仅为每个html文件中的每个标签提取特定内容?

This is a perfect use case for ng-include . 这是ng-include的完美用例。 As per the Documentation , it fetches, compiles and includes an external HTML fragment. 根据文档 ,它可以fetches, compiles and includes an external HTML fragment.

Use it like this: 像这样使用它:

Javascript 使用Javascript

$scope.templates = [
  { URL: '/path/to/file.html' },
  { URL: '/path/to/file2.html'}
]

HTML HTML

<div ng-repeat="template in templates">
  <div ng-include="template.URL">
    <!-- Template markup goes here -->
  </div>
</div>

And that's it. 就是这样。 Just make sure that file.html and file2.html exist, and you can just drag your markup right into each corresponding one. 只需确保file.html和file2.html存在,您只需将标记拖动到每个相应的标记即可。

Edit: Following on from your comment to Pangolin's answer: Plunker 编辑:继续你的评论到Pangolin的回答: Plunker

JS JS

app.directive("fruit", function() {
    return {
        restrict: "E",
        templateUrl: "fruit.html"
    };
});

HTML HTML

  <tab ng-repeat="tab in tabs" heading="{{tab.title}}" select="getContent($index)" active="tab.active" disabled="tab.disabled">
  <div ng-hide="!tabs.isLoaded">
    <fruit></fruit>
  </div>
  <div ng-hide="tabs.isLoaded"><h3>Loading...</h3></div>
  </tab>

fruit.html (trimmed version) fruit.html(修剪版)

<div ng-show="tab.title=='Apple'">
<h2>Apple</h2>
<p>The apple tree....
</div>

<div ng-show="tab.title=='Pear'">
<h3>Pear</h3>
<p>The pear is 
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM