javascript - AngularJS 加载个人用户配置文件

标签 javascript php angularjs

我是 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/

相关文章:

javascript - 根据指针字段值过滤解析查询

javascript - 为什么不能同时使用ajax和服务器发送事件?

php - 如何检测站点访问者是否通过 Citrix XenApp 浏览站点?

javascript - 使用 Web API Get() 正确格式化 JSON

javascript - 有什么方法可以删除 HTML 元素中的 Angular 属性吗?

javascript - 聚焦时如何使用 Angular 将输入字段滚动/移动到屏幕顶部?

javascript - 如何禁用下拉选择中的一个选项?

javascript - 如何在 JavaScript 中对数组进行排序

php - 如何在php项目中使用Piwik设备检测器?

angularjs - 何时使用 ng-if 与 ng-show/ng-hide?