0

I'm working on single page aplication based on Angular. I want to do something like card stack made from divs. Like this.

enter image description here

Idea is that app will have some url links and card should be append when url changes. For example I have 4 links. Home | About | Contacts | Details

On page load will append home card then About etc. So url will change and next card should append.

So my question is: how append some html block when url changes in Angular? I mean that url will be changed but view should be the same and I want just append some html to existing view

Thanks

1 Answer 1

0

If using ui.router you can do it like this and update the scopes with the images.

Here is a code example

'use strict';

angular
  .module('myApp', [
    'ui.router'
  ])
  .config(function ($locationProvider, $stateProvider, $urlRouterProvider, $compileProvider) {

    // define states
    $stateProvider
    .state('home', {
      url: '/',
      templateUrl: 'views/home.html'
    })
    .state('about', {
      url: '/about',
      templateUrl: 'views/about.html'
    });

    // define alternative route
    $urlRouterProvider.otherwise('/');

  })

  .run(function ($rootScope) {

      // image changes with route change
      if(toState.url === '/') {
        $rootScope.headerImg = 'images/headers/home.jpg';
      } else if (toState.url === '/about') {
        $rootScope.headerImg = 'images/headers/about.jpg';
      } else {
        $rootScope.headerImg = 'images/headers/error.jpg';
      }

    });

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

7 Comments

thanks for the answer. I think there is misunderstanding. I do not want to change views. Can I just append html code to existing view on url change?.
Sure. You can use the same view for multiple routes... Then you can check if the route is correct and set the correct image.. That is happening in my code in lines following after //images The image changes with the different routes. The view doesn't if you use same view for multiple routes.
will the view reload when route changes?
Check this on your own ;)
Sure, see here or use google ;)
|

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.