0

So, I have a list of items in an Ionic framework project, like this:

 <a ng-repeat="item in items" href="#/item/{{item.id}}" ng-click="clicker(item)" class="item item-thumbnail-left">

Being a noob in AngularJS, I don't know how to generate random states using state providers. Urls look like this: /item/1, /item/2, /item/3, etc.

What am I trying to achieve:

  • define a template
  • load some content in that template, dynamically (for each item, i have different content)

Is this possible? If so, how?

2
  • Do you mean "dynamic content" as the data from an AJAX call based on the id or just static HTML files? Commented Oct 10, 2015 at 14:43
  • @ShashankAgrawal For the moment that's not important. I'm trying to just open a new "page" when i click a list item. After that, passing the id must be easy, i guess. Right now just static html files Commented Oct 10, 2015 at 14:44

1 Answer 1

1

Yes, it's absolutely possible. First take a bit look about defining state and using state manager https://github.com/angular-ui/ui-router/wiki

Now, define a state like:

.state('itemView', {
    url: '/item/:id',
    templateUrl : function($stateParams) {
        // Your path to the view
        return 'views/items/display' + $stateParams.id + '.html';
    }
})

Now your click on anchor link should render the page based on the id considering you have static HTML files named as views/items/display1.html

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

2 Comments

Thank you. The page is not rendering, but I understood the idea. Clicking on an item right now, does nothing.
Glad this helps! The documentation of ui-router is pretty good. Please try to read it from the start, you will definitely make your page running.

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.