【问题标题】:Angular stateprovider always hits 'otherwise' stateAngular stateprovider 始终处于“否则”状态
【发布时间】:2017-02-19 14:02:42
【问题描述】:

我试图在解析 1 个参数时通过控制器设置状态。 据我所知,首选状态被调用,但是“其他”状态随后立即加载。 我发现通过点击后退按钮调用了首选状态。 单击后退按钮时,将调用首选状态。 在我的 stateprovider 设置中似乎是一个小问题,但我根本无法找到它。

以下是我的 controller.js 文件的一部分。

.controller('resultsCtrl', ['$scope', '$stateParams', 'searchfactory', '$state',
function ($scope, $stateParams, searchfactory, $state) {
    $scope.results = searchfactory.getresults();
    console.log($scope.results);
    $scope.showdoc = function(docid){
        console.log(docid);
        $state.go('doctor', { docid: docid });
    }
}])

.controller('doctorCtrl', ['$scope', '$stateParams', 
function ($scope, $stateParams) {
    alert($stateParams.docid);

}])

下面是我处理“医生”部分的路线文件。

.state('doctor', {
    url: '/doctor/{docid}',
    templateUrl: 'templates/doctor.html',
    controller: 'doctorCtrl'
  })

点击后退按钮后,网址显示为http://192.168.8.100:8100/#/doctor/11,我认为这是正确的网址。 此外,警报也会弹出。在警报上单击“确定”按钮后完成重定向。

非常感谢您的帮助。

【问题讨论】:

  • templates/doctor.html 存在吗??
  • @SaurabhAgrawal 你好。是的
  • 也不确定是否有帮助。但是当我转到192.168.8.100:8100/#/doctor/11 url 并刷新它时,它会停留在那里。不会被重定向
  • 检查您是否在视图中使用href
  • 当你说 href 时,我就知道有些可疑。原来我有 href="#" 和进行重定向的 ng-click。现在可以了。非常感谢

标签: javascript angularjs ionic-framework


【解决方案1】:

检查是否有templates/doctor.html existhref他们。

【讨论】:

    猜你喜欢
    • 2016-10-09
    • 2014-06-28
    • 1970-01-01
    • 2014-09-20
    • 2016-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多