data-toggle =“dropdown”激活路由重定向而不是自动下拉

时间:2015-02-05 07:11:31

标签: javascript angularjs node.js twitter-bootstrap yeoman

我正在使用angular-bootstrap-datetimepicker,特别是"下拉日期时间和输入框"。它使用data-toggle="dropdown"属性。当我在一个简单的nodejs express服务器上运行我的AngularJS App时,日历出现了。自从我迁移到自耕农后,点击下拉菜单会激活重定向到/#http://localhost:9000/#

这就是我在视图中使用datetimepicker的方式:

dtpform.html

<div class="dropdown">
    <a class="dropdown-toggle" id="dropdown2" role="button" data-toggle="dropdown" data-target="#" href="#">
        <div class="input-group"><input type="text" class="form-control" data-ng-model="startDate"><span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
        </div>
    </a>
    <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
        <datetimepicker data-ng-model="startDate" data-datetimepicker-config="{ dropdownSelector: '#dropdown2', minView: 'hour' }"/>
    </ul>
</div>

其他有同样问题的人忘了一些依赖。我似乎已经全部准备好了。如果我将datetimepicker插入index.html而不是/ dtp路由,它会弹出。

的index.html

...
<!-- build:js(.) scripts/vendor.js -->
<!-- bower:js -->
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="bower_components/angular-animate/angular-animate.js"></script>
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
<script src="bower_components/angular-resource/angular-resource.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="bower_components/angular-touch/angular-touch.js"></script>
<script src="bower_components/moment/moment.js"></script>
<script src="bower_components/angular-moment/angular-moment.js"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script src="bower_components/angular-bootstrap-datetimepicker/src/js/datetimepicker.js"></script>
<!-- endbower -->
<!-- endbuild -->
...

app.js

angular
  .module('c2gyoApp', [
    'ngAnimate',
    'ngCookies',
    'ngResource',
    'ngRoute',
    'ngSanitize',
    'ngTouch',
    'angularMoment',
    'ui.bootstrap',
    'ui.bootstrap.datetimepicker'
  ])
  .config(function($routeProvider) {
    $routeProvider
      ...
      .when('/dtp', {
        ...
        templateUrl: 'views/dtpform.html',
        ...
      }).
    otherwise({
      redirectTo: '/c2g'
    });
  });
  ...

任何想法是什么导致了这种行为?

1 个答案:

答案 0 :(得分:6)

href="#"似乎是个问题。 href标记将告诉角度路由器导航到匹配/#的路由。如果你删除它,下拉列表应该打开确定。