admin管理员组文章数量:1026380
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
2 Answers
Reset to default 4Basically 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
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
2 Answers
Reset to default 4Basically 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
本文标签: javascriptHow to do load page in Angular JSStack Overflow
版权声明:本文标题:javascript - How to do load page in Angular JS? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745643443a2160883.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论