Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Master Page Concept in AngularJS?

Tags:

angularjs

I would like to create master page, that is main page which will be used in all views of the application.

For example, Left navigation and top men navigation. This navigation should be displayed in all the views, whenever url changes in application.

enter image description here

As per ng-view, it only renders given partial view and replace previous view. In the image above all my left and top navigation should be displayed by using angular Controller.

Controller code

angular.module('modelDemo').controller("authCtrl", ['$scope', function($scope) {
      $scope.list;
}]);

Please let me know, how can i achieve this

like image 484
niran Avatar asked Apr 30 '13 03:04

niran


People also ask

What is master page in angular?

Solution. My career in web development started with ASP.NET which has the concept of master pages: a page that defines the layout of the web application and has placeholders for the content. The actual pages defined components that live in those placeholders.

What is workflow in AngularJS?

Extending an AngularJS Workflow¶ A workflow extends the extensibleService . This means that all workflows inherit properties and methods provided by the extensibleService . Extending a workflow allows you to add your own steps, remove existing steps, and inject custom data handling logic.

What is $$ in AngularJS?

The $ in AngularJs is a built-in object.It contains application data and methods.

What are templates in AngularJS?

Templates in AngularJS are simply an HTML file filled or enriched with AngularJS stuff like attributes and directives. A directive is a marker element that is used to target a particular attribute or class to render its behavior as according to the needs.


2 Answers

You can use angular-route or Angular-ui-router, and setting your master, following this steps:

  • Step 1. Make your index.html your master page.
  • Step 2. Add the <header>, <footer>, <aside>, <div>, etc. referencing your templates by using ng-include
    • NOTE: your left and top navigation will be part of it
  • Step 3. The content of the view will be rendered using the directive attribute ng-view or ui-view
  • Step 4. Use your module app.config() to configure the children pages

enter image description here

Source:

  • using Angular Route: https://docs.angularjs.org/tutorial/step_07
    • template for a brand-new app: https://github.com/angular/angular-seed
  • using Angular UI Router: Angular Tutorial 30 mins
like image 60
Jaider Avatar answered Sep 22 '22 02:09

Jaider


ng view should be able to do that just fine. Keep your top navigation / left navigation html intact and use ng view for the various display area. http://docs.angularjs.org/api/ng.directive:ngView

To use the controller from the top navigation inside ng-view you can use $parent to get access to that scope : https://stackoverflow.com/a/14700326/390330

Fiddle for parent scope : http://jsfiddle.net/ezhrw/2/

<button ng:click="$parent.letter = greek">Assignment expression {{ greek }}</button>
like image 37
basarat Avatar answered Sep 24 '22 02:09

basarat