【问题标题】:this part of the ion-nav-view documentation doesn't make sense to meion-nav-view 文档的这一部分对我来说没有意义
【发布时间】:2016-10-07 19:38:34
【问题描述】:

ion-nav-view 指令的示例代码实际上并未显示其用法。 所以我不确定如何使用它。 这是文档的链接:

http://ionicframework.com/docs/api/directive/ionNavView/

USAGE 标题下是这样写的:

在应用启动时,$stateProvider 会查看 url,看是否匹配 索引状态,然后尝试将 home.html 加载到 .

页面由给定的 URL 加载。创建模板的一种简单方法 在 Angular 中是将它们直接放入您的 HTML 文件并使用 句法。所以这是一种放置方式 home.html 进入我们的应用程序:

<script id="home" type="text/ng-template">

  <!-- The title of the ion-view will be shown on the navbar -->
  <ion-view view-title="Home">
    <ion-content ng-controller="HomeCtrl">
      <!-- The content of the page -->
      <a href="#/music">Go to music page!</a>
    </ion-content>
  </ion-view>

</script>

这样做很好,因为模板将被缓存得非常快 加载,而不必从网络中获取它们。

我是否将所有这些都嵌套在 ion-nav-view 指令中?我感到困惑的另一个原因是因为在框架提供的一个 ionic 模板中,我看到 ion-nav-view 打开和关闭,中间没有任何内容(下面的代码是直接从 Ionic 的一个模板复制和粘贴的):

 <body ng-app="myApp">

    <!--
          The nav bar that will be updated as we navigate between views.
        -->
        <ion-nav-bar class="bar-stable">
          <ion-nav-back-button>
          </ion-nav-back-button>
        </ion-nav-bar>
        <!--
          The views will be rendered in the <ion-nav-view> directive below
          Templates are in the /templates folder (but you could also
          have templates inline in this html file if you'd like).
        -->

        <ion-nav-view></ion-nav-view>

    </body>

【问题讨论】:

    标签: ionic-framework nav ionic-view


    【解决方案1】:

    这个&lt;ion-nav-view&gt; 的行为类似于占位符。您在模板文件夹下创建的其他 html 文件位于其中。因此,例如,您的模板文件夹中有“employees.html”。所以“employees.html”的标记看起来像这样:

    <ion-view view-title="Employees">
    <ion-content>
      <ion-list>
        <ion-item ng-repeat="item in items">
          Hello, {{item}}
        </ion-item>
      </ion-list>
    </ion-content>
    </ion-view>
    

    以上是完整的 html,将位于“employees.html”中。基本上这是将放置在&lt;ion-nav-view&gt; 标签内的html。

    希望这会有所帮助。

    【讨论】:

    • 所以我使用 ion-nav-view 如模板代码所示?意思是我把空指令放在那里,让 angular 做剩下的?
    • 没错。它通过路由器配置发生。看到你有这样的东西 '' 然后在你的 app.js 你的状态配置中你用这种方式定义它 .state(' app.homepage', { cache: false, url: '/homepage', 视图: { 'menuContent': { templateUrl: 'templates/homepage.html', controller: 'HomepageCtrl' } } })跨度>
    • 知道了。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-23
    • 2015-02-14
    • 1970-01-01
    • 2018-05-05
    相关资源
    最近更新 更多