Dynamic templateUrl

30 views
Skip to first unread message

mark goldin

unread,
Sep 19, 2014, 3:26:48 PM9/19/14
to ang...@googlegroups.com
Let's say I have a following state definition:
app.config(function ($stateProvider, $urlRouterProvider) {
    $stateProvider
      .state('first', {
        url: '/first',
        views: {
          upper: {
          templateUrl: 'app/views/partial1.html'
          },
          lower: {
                templateUrl: 'app/views/partial2.html'
          }
        }
      })
  });

What I'd like to do is to have lower view with a dynamic template meaning I can load different views into it. Is that possible?

Thanks

Mark Volkmann

unread,
Sep 19, 2014, 4:51:52 PM9/19/14
to ang...@googlegroups.com
You can use templateProvider instead of templateUrl inside the definition of "lower" to specify a function that will built and return the HTML you want for that part of the view.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.



--
R. Mark Volkmann
Object Computing, Inc.

mark goldin

unread,
Sep 19, 2014, 5:15:36 PM9/19/14
to ang...@googlegroups.com
Yes, I figured that out too. I am now getting different views based on some conditions:
templateUrl: function ($stateParams){
   return 'app/views/' + $stateParams.partialURL + '.html';
}
But the thing is I only want to refresh lower view. If I $state.go to state 'first' both views are refreshed. Can I 'go' lower view directly or something?

Thanks

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/cQhBbjheKus/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages