javascript - Ionic 和 Angular 指令的基本问题

标签 javascript angularjs ionic-framework

我正在使用 Ionic 开发一个项目,因此我也使用 Angular 1。 我不太了解这个框架(我真的更喜欢 Google 对 Angular 2 所做的事情:-))。

基本上,我只想创建一个新的 HTML 元素(指令)并在我的 ionic 应用程序的 View 中使用它。

以下是我声明指令的方式:

app.directive('smLocationSheet', function() {
   return {
      restrict: 'E',
      transclude: true,
      replace: true,
      scope: {},
      templateUrl: './locationSheet.html'
   }
});

我有一个非常基本的静态 HTML 模板和一些 SCSS,但这并不重要。在我的 home.html 中,我想像这样使用我的指令:

<ion-view id="homeView" style="position: static !important;" view-title="Accueil" ng-init="init()">
    <ion-content class="has-tabs">
        <div id="map" data-tap-disabled="true"></div>
        <sm-location-sheet></sm-location-sheet>
    </ion-content>
</ion-view>

描述该指令的 js 文件已正确加载,但我的指令未“渲染”。在调试过程中,我可以看到 html 标签 sm-location-sheet 但没有模板。另外,它应该被我的 hmtl 文件替换。

最佳答案

嗯,多亏了dfsq,我找到了我的问题。模板未加载。 以下是一些有用的链接,可以帮助您了解原因(尤其是 ionic :)):

Couldn't load template using templateUrl in Angularjs

AngularJS Failed to load template

关于javascript - Ionic 和 Angular 指令的基本问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36531106/

相关文章:

javascript - 将新对象插入到特定数组索引中

node.js - 无法在 npm 上安装 cordova ionic

javascript - Ionic imagePicker 未打开图库

javascript - JS-Ooyala API : How do I return this objects title property?

javascript - 右键单击标记 - Google map V3

javascript - Koa cookie 返回 `undefined`

angularjs - Angular 一次向多个模块添加服务

javascript - 日期比较 Angular JS

html - 在 Ionic3 中使用 SCSS 为页面上所有元素的背景和文本着色

javascript - 如何返回一个列表,其中一个数组中的数据被另一个数组过滤