最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How to do load page in Angular JS? - Stack Overflow

matteradmin7PV0评论

How to load content on page by clicking on menu links? For example, there is menu:

<a href="#">Personal</a>
<a href="#">Contacts</a>

Question is in how change template HTML in page for each link?

How to load content on page by clicking on menu links? For example, there is menu:

<a href="#">Personal</a>
<a href="#">Contacts</a>

Question is in how change template HTML in page for each link?

Share Improve this question edited Jun 28, 2017 at 5:41 laser 1,37613 silver badges14 bronze badges asked May 2, 2015 at 12:29 HamedHamed 4102 gold badges13 silver badges21 bronze badges 1
  • 2 check out ng-view docs.angularjs/api/ngRoute/directive/ngView – Artem Petrosian Commented May 2, 2015 at 12:32
Add a ment  | 

2 Answers 2

Reset to default 4

Basically what you are trying to achieve will be acplish by creating SPA. For that you need to use ngRoute module in your application(by adding angular-route.js)

For setting up angular router you need to register routes with there template & controller, etc. inside app.config.$routeProvider would take a URL by .when method.

Code

  var app= angular.module('app', ['ngRoute']);
  app.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider.
      when('/tab/:id', {
        templateUrl: 'template.html',
        controller: 'templateController'
      }).
      otherwise({
        redirectTo: '/tab/1'
      });
  }]);

& then there would be one section on UI which is nothing but ng-view directive that watches of $routeProvider configuration with url in browser bar

<ng-view></ng-view> 

For more details look at this answer

Working Example Plunkr

Additional to @pankaj, You have to use $location services in your controller. So that you can change view accordingly from controller.

ex. You have link

<a ng-click="saveData">Save</a>

Now in controller:

$scope.saveData = function(){
     $location.href('viewName');
}

ref : https://docs.angularjs/api/ng/service/$location

Post a comment

comment list (0)

  1. No comments so far