Ionic v1 - $ ionicModal - ' fromTemplateUrl'未定义

时间:2017-06-05 09:55:03

标签: ionic-framework

我关注如何实施$ ionicModel

的文档

http://ionicframework.com/docs/v1/api/service/ $ ionicModal /

但是,我收到了错误:

  

TypeError:无法读取属性' fromTemplateUrl '未定义的

我的控制器:

.controller('barCtrl', ['$scope', '$stateParams', '$ionicHistory', '$rootScope', '$ionicModal',
function ($scope, $stateParams, $ionicHistory, $rootScope, $cordovaInAppBrowser, $ionicModal) {
    /* Modal */
    $ionicModal.fromTemplateUrl('/templates/bar.html', {
        scope: $scope,
        animation: 'slide-in-up'
    }).then(function (modal) {
        $scope.modal = modal;
    });
    $scope.openModal = function () {
        $scope.modal.show();
    };
    $scope.closeModal = function () {
        $scope.modal.hide();
    };
    // Cleanup the modal when we're done with it!
    $scope.$on('$destroy', function () {
        $scope.modal.remove();
    });
    // Execute action on hide modal
    $scope.$on('modal.hidden', function () {
        // Execute action
    });
    // Execute action on remove modal
    $scope.$on('modal.removed', function () {
        // Execute action
    });

}])

模板:

    <script id="bar.html" type="text/ng-template">
        <ion-modal-view>
            <ion-header-bar>
                <h1 class="title">My Modal title</h1>
            </ion-header-bar>
            <ion-content>
                Hello!
            </ion-content>
        </ion-modal-view>
    </script>

1 个答案:

答案 0 :(得分:3)

您的订单错误依赖。

更改此

.controller('barCtrl', ['$scope', '$stateParams', '$ionicHistory', '$rootScope', '$ionicModal',
function ($scope, $stateParams, $ionicHistory, $rootScope, $cordovaInAppBrowser, $ionicModal) 

.controller('barCtrl', ['$scope', '$stateParams', '$ionicHistory', '$rootScope', '$ionicModal',
    function ($scope, $stateParams, $ionicHistory, $rootScope, $ionicModal)