dqx36753 2015-08-21 09:09
浏览 47

角度模板文件中的Bootstrap JS无效

Is there a way to have bootstrap js directives (inline tag attributes) work within a angular template file?

All JS libs are correctly loaded, including the js init code for using popovers. The angular template is correctly loaded using angular router.

All the bootstrap js functions fail to be run/detected in angular templates, is there something i'm doing wrong or is this expected, and is there a way to get it working without changing the html (I looked at angular bootstap ui, but it requires rewriting the html)

Super simplified:
Twig template:

<div class="col-md-12" ng-app="builderApp"><div ng-view></div></div>

Angular template:

<i class="fa fa-info-circle" data-toggle="popover" data-content="woop woop"></i>

Angular JS:

var builderApp = angular.module('builderApp', ['ngRoute', 'xeditable']);
    builderApp.config(['$routeProvider', function($routeProvider) {
        $routeProvider.
            when('/', {
                templateUrl: template_path + 'root.html',
                controller: 'rootController'
            })
    }]);
    builderApp.controller('rootController', function($scope, directoryFactory) {
        $scope.directory = directoryFactory.getDirectory();
    });
  • 写回答

1条回答 默认 最新

  • douzhenggui8171 2015-08-21 13:56
    关注

    I would most certainly use the Angular Bootstrap Directive. I've never seen it done any other way. This will give you access to the typical bootstrap CSS as well as the interactive functions in the angular bootstrap. I also prefer to use ui router.

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"/>
    <script src="scripts/vendors/ui-router-master/release/angular-ui-router.min.js"></script>
    <script src="scripts/vendors/ui-bootstrap-tpls-0.13.0.min.js"></script>
    
    
        var app = angular.module('BuilderApp', ['ui.router','ui.bootstrap']);
    
        app.config(['$stateProvider', '$urlRouterProvider',
            function ($stateProvider, $urlRouterProvider) {
                $urlRouterProvider.otherwise("/login");
                $stateProvider
                  .state('login', {
                      url: '/login',
                      title: 'Login',
                      templateUrl:'views/loginView.html',
                      controller: 'loginCtrl'),
    
                  })
                  .state('account', {
                      url: '/account',
                      title: 'My Account'
    
    
                      views: {
                        'navigation': {
                             templateUrl: 'views/navigationView.html',
                             controller: 'navigationCtrl'
                        },
                        'content': {
                            templateUrl: 'views/contentView.html',
                            controller: 'navigationCtrl'
                        }
                     }            
                  })
                .state('account.dashboard', {
                     url:'/dashboard',
                     title: 'Dashboard',
                     views : {
                        'pageContent': {
                            templateUrl:'views/dashboardView.html',
                            controller: 'dashboardCtrl'
                    }   
                 }             
              })
    

    And then make sure to inject the router into your controller.

    app.controller('navigationCtrl', function ($scope, $stateParams, $location, $state) {
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)