我是 AngularJS 的新手,正在尝试创建一个小型服务作为学生项目。
我在 http:.../profile.html
下有一个可用的 html5 模板
这个模板是“angularJS友好的”,这意味着我可以从Rest加载我的profile.html中的任何个人资料信息(例如带有{{user.username}}的用户名,...)服务为我提供适当的json
现在,当我想加载 http:../profile/{usernameXYZ}
时,如 PHP /profile.php?username=usernameXYZ
我该怎么做?
更具体地说:我如何创建/加载/??? AngularJS 中只有一个模板的个人资料页面
最佳答案
您需要添加“ngRoute” ' 作为应用程序中的依赖项
angular.module('ngApp', ['ngRoute'])
.config(function ($routeProvider, $locationProvider) {
//configure the routing rules here
$routeProvider.when('/profile/:username/', {
controller: 'PagesCtrl'
});
//routing DOESN'T work without html5Mode
$locationProvider.html5Mode(true);
})
.controller('PagesCtrl', function ($rootScope, $scope, $routeParams, $route) {
//If you want to use URL attributes before the website is loaded
$rootScope.$on('$routeChangeSuccess', function () {
console.log($routeParams.username)
});
});
现在您将能够在此 route 导航您的应用程序 http://...../profile/testUserName
关于javascript - AngularJS 加载个人用户配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28171058/