【问题标题】:How to use templateUrl in AngularJS?如何在 AngularJS 中使用 templateUrl?
【发布时间】:2015-02-08 13:04:38
【问题描述】:

在我的文件 home.js 中有

.state('app.profile', {
    url : '/profile',
    views : {
        'appContent' : {
            templateUrl: '../templates/profile.html',
            controller: 'HomeController'
        }
    }
})

在我的文件 profile.html 中有这个

<ion-view title="Profile">
  <ion-content>
    <!--somethings here-->
  </ion-content>
</ion-view>

我的目录

js
  home.js
templates
  profile.html

但我不能让它工作。请帮我解决这个错误!

【问题讨论】:

  • 这个老问题似乎无法解释问题是什么,所以我投票结束。如果可以,请编辑。

标签: javascript html templates state angularjs-routing


【解决方案1】:

如果我理解正确,你必须这样做:

.state('index', {
    url : '/route1',
    templateUrl: '../templates/profile.html',
    controller: 'Controller'
})

如果您想使用多个视图:

.state('index', {
    url: "/route1",
    views: {
      "viewA": { template: "index.viewA" },
      "viewB": { template: "index.viewB" }
    }
}) 

【讨论】:

  • 不不,我的意思是:我的 index.html 文件中有这段代码 但我想将它们分成2个文件。我将
猜你喜欢
  • 1970-01-01
  • 2012-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-21
  • 2013-01-23
  • 1970-01-01
相关资源
最近更新 更多