角$ routeParams是空白 [英] Angular $routeParams is blank

查看:109
本文介绍了角$ routeParams是空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我已经蒸馏下面一个非常简单的应用角度:

I have a really simple Angular app that I've distilled to the following:

var napp = angular.module('Napp',['ngResource']);

var CompanyCtrl = function($scope, $routeParams, $location, $resource) {
    console.log($routeParams);
};


napp.config(['$routeProvider', function($routeProvider) {
    $routeProvider
    .when('/company/edit/:id', 
      {templateUrl: '/partials/edit', controller: 'CompanyCtrl'}
    );
}]);

和HTML:

<div ng-controller="CompanyCtrl"></div>

当我登录$ routeParams,它出现空白。当我使用。否则(),它会加载无论我指定了那里。任何想法,我缺少什么?

When I log $routeParams, it comes up blank. When I use .otherwise(), it will load whatever I've specified there. Any idea what I'm missing?

推荐答案

所有的第一次尝试这种以

First of all try this with

$locationProvider.html5Mode(true);

这应该解决您的出发code。然后调整code支持非pushState的浏览器。

That should fix your starting code. Then adjust your code to support non-pushState browsers.

希望这有助于!

这篇关于角$ routeParams是空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆