Now, I want to use the same HTML to represent a customer in another ionic view (Dashboard).
I wonder about the best practice now to re-use this piece of HTML.
Would it be recommended to define a new state for the template? If yes, how can I embed the template then in a list ('re-use it")? I tried this approach but failed with it, as I did not find out how to embed the template in a ion-list.
<ion-view view-title="New Customers" ng-controller="CustomerCtrl">
<ion-content>
<ion-list>
<ion-item ng-repeat="c in customerlist">
<< how can I use/embed the template "customer.short.html" here? >>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
Sorry, I did not understand your question.
This is not an Ionic question, it’s an angular-ui router basic question, you should just read a tutorial on angular ui-router.
states and uiRouter are used for when you want something to happen when someone clicks a URL, not for when you want to re-use bits of html in an ng-repeat.
Thanks a lot jawache! That tip solves my problem. I was on the wrong way trying to use states for that.
Little correction: When unsing ng-include, it seems that the path to the template expects an expression, so the path needs to be packed into single quotes:
I think I have a problem with ng-Include in combination with Ionic directives, in my case the OptionButtons of the list (accessed by swiping left) show not up in case I use them inside ng-include:
Working code without ng-include (swiping/option works - buttons show up when swiping):
I agree with jawache. I think that usage of custom directives makes sense when you need to hide away complex logic behind a single directive (facade pattern).
With simple issues like in my case, the code is more readable using standard directives and tags.
@pmigabreu: What are your pro arguments for using a directive here?
Now that I think of it, it makes sense in this case to be loaded via include instead of a directive because there is no logic specific for this template.
I tend to make directive a instead with this in mind, that at some point it will have some underlying logic (that’s how I can justify my way of thinking)
Generally (not always) my advice with directives and most other things in dev is don’t bother making it re-usable until you use it 3 times, i.e. if this is the 3rd time you are copying and pasting some code then make it re-usable.