AngularJs:控制器使用$ routeProvider叫了两声 [英] AngularJs: controller is called twice by using $routeProvider

查看:119
本文介绍了AngularJs:控制器使用$ routeProvider叫了两声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

模块路线:

var switchModule = angular.module('switchModule', []);

switchModule.config(['$routeProvider', function($routeProvider) {
    $routeProvider.
    when('/build-content', {templateUrl: 'build-content.html', controller: BuildInfoController});
}]);

控制器:

function BuildInfoController($http, $scope){
    alert("hello");
}

HTML:

<html ng-app="switchModule">
...
<body>
    <ul>
        <li><a href="#build-content"/></a></li>
    </ul>
    <div class="ng-view"></div>
</body>
...

每个当我点击超链接'的'BuildInfoController的时间将被调用两次。我思念的东西在这里?

Each time when i click the hyperlink '', the 'BuildInfoController' will be called twice. Am i missing something here?

推荐答案

我有同样的问题,而且似乎没有与路由一个愚蠢的错误。有某种重定向的事情。

I had the same problem , and it seems there is a stupid bug with routing. There is some kind of redirection going on.

要修复它,我只是在href加斜杠,如:

to fix it , i just added a slash in the href , like :

<li><a href="#/build-content/"></a></li>

我希望它会解决的事情对你来说。

I hope it will fix things for you too.

这篇关于AngularJs:控制器使用$ routeProvider叫了两声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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