在控制器之外创建角度模态

时间:2016-09-21 17:39:38

标签: javascript angularjs

<?php /** * My Orders * * Shows recent orders on the account page. * * This template can be overridden by copying it to yourtheme/woocommerce/myaccount/my-orders.php. * * HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer). * will need to copy the new files to your theme to maintain compatibility. We try to do this. * as little as possible, but it does happen. When this occurs the version of the template file will. * be bumped and the readme will list any important changes. * * @see http://docs.woothemes.com/document/template-structure/ * @author WooThemes * @package WooCommerce/Templates * @version 2.5.0 */ if ( ! defined( 'ABSPATH' ) ) { exit; } $my_orders_columns = apply_filters( 'woocommerce_my_account_my_orders_columns', array( 'order-number' => __( 'Order', 'woocommerce' ), 'order-date' => __( 'Date', 'woocommerce' ), // 'order-status' => __( 'Status', 'woocommerce' ), 'order-total' => __( 'Total', 'woocommerce' ), 'order-actions' => '&nbsp;', ) ); 中,特别是在app.js内,我有一个创建模态的函数:

$rootScope.$on('$routeChangeStart')

我得到了setIdleTimeout.$inject = ['$uibModal'] function setIdleTimeout(timerStart, timerDuration, $scope, $uibModal){ console.log('timerStart: ', timerStart, 'timerDuration: ', timerDuration) setTimeout(function(){ console.log('setTimeout running') var modalInstance = $uibModal.open({ animation: $scope.animationsEnabled, templateUrl: '****', controller: '****', scope: $scope, size: size, backdrop : 'static', resolve: {} }); modalInstance.result.then(function (selectedItem) { $scope.selected = selectedItem }, function () { }) }, 10000) } ,即使是我正在注入它并将源代码包含在Uncaught TypeError: Cannot read property 'open' of undefined

Index.html

如何在控制器外创建模态?

1 个答案:

答案 0 :(得分:1)

可能需要有关代码结构的更多详细信息,特别是您调用$ rootScope的上下文。$ on()...

我认为你在这里遇到的问题$uibModal没有正确注入。不是在$inject函数中使用setIdleTimeout,而是尝试将$uibModal注入与注入$rootScope的位置相同的级别。