7

I am using Ionic framework to create an application.

I need to be able to reuse and change my app header so I declare my two different headers as directives using my working markup.

app.directive('headerSidebar', function(){
  return {
    templateUrl: 'templates/header-main.html',
    restrict: 'E'
  };
});

app.directive('headerBack', function(){
  return {
    templateUrl: 'templates/header-back.html',
    restrict: 'E'
  };
});

When I try to call the directives with <header-sidebar></header-sidebar> or <header-back></header-back> nothing happens.

My html is valid and my template urls are correct. I have tried changing the names of both my directives and my templates but nothing worked.

I am using the Ionic sidebar layout and I call my directives inside my ion-nav-view:

 <body ng-app="starter">

    <ion-side-menus>

      <ion-side-menu-content>
        <ion-nav-view></ion-nav-view>
      </ion-side-menu-content>

      <sidebar></sidebar>

    </ion-side-menus>

  </body>

Any suggestions to how I could solve this or reorganize my code to better include the header bars?

6
  • I'm just now running into this same problem. It appears that any directive with a templateUrl will not load that template externally once the app is built in iOS. Were you able to figure this issue out? Commented Jan 18, 2015 at 22:07
  • I haven't solved it yet. I gave up and copied the markup in everywhere. I have the problem even before built. Commented Jan 22, 2015 at 9:05
  • 4
    My issue ended up being a little bit different than yours I guess. Upon further inspection I realized that I had a '/' before all of my templateUrls that was actually causing the issue. Commented Jan 22, 2015 at 15:43
  • Same thing with templateUrl not rendering directives on android Commented Jun 4, 2015 at 20:09
  • @WillHitchcock Thank you very much, this did the trick for me! Commented Aug 20, 2015 at 13:38

2 Answers 2

9

My issue ended up being a little bit different than yours I guess. Upon further inspection I realized that I had a '/' before all of my templateUrls that was actually causing the issue

Sign up to request clarification or add additional context in comments.

2 Comments

Had a similar issue, the problem was with the template url having ../ at the front of it
Relative paths work great in the browser, but not in the compiled app. Thanks Will for saving me on this one :)
0

I had the similar issue. This is due to the relative path in URL. This works fine in the browsers but not in App. I removed ../ from the URL path.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.