我正在使用 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 :)):
关于javascript - Ionic 和 Angular 指令的基本问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36531106/