1

I am beginner in AngularJS and I find it hard to understand the flow.

I have a HTML to start with and given a link there

< a href="#/secondHTML"> GO < /a>

When I click on the 'a' tag where it should go. - to the state named 'secondHTML' - to the HTML named 'secondHTML'

Please explain in detail the architecture of AngularJS

1 Answer 1

3

AngularJS uses Routes. #/secondHTML is a route, which is usually mapped to a template partial, which contains the HTML needed to render the view.

Usually inside app.js is where the code that configures your routes will be.

The code probably looks like:

angular.module('isweb', [
  'isweb.controllers',
  'isweb.filters',
  'isweb.services',
  'isweb.directives',
]).
config(['$routeProvider','$locationProvider',function ($routeProvider, $locationProvider) {
  $routeProvider.
    when('/secondHTML', {
      templateUrl: 'partials/page2',
      controller: 'page2Ctrl'
    }).
    otherwise({
      redirectTo: '/firstHTML'
    });
}]);

Notice the config method, which takes the routeProvider, as well as the mappings between the URL and the actual URL for the partial template.

So when you go to: #/secontHTML AngularJS will actually request partials/page2 from the server, and render that. However, the address bar will look something like myapp.com/app#/secondHTML

I HIGHLY recommend going through the AngularJS tutorial.

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

2 Comments

How we can achieve this using states?
Look at using Angular UI-Router.

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.