angularJS模态打开不起作用

时间:2018-04-04 15:17:21

标签: javascript angularjs

我有一个html文件。 在那个文件中,我有一个按钮,当我点击它时应该打开一个模态。

   <button ng-click="open(value.Reservation.id)" class="btn btn-default btn-xs" ></button>

并在该按钮下方,在同一个html文件中,我有脚本。

   <script type="text/ng-template" id="myModalContent.html">test</script>  

并在pendingController.js文件中,

   myApp.controller('PendingCtrl', function ($rootScope, $scope, $location, $http, $modal, $log) {

$scope.open = function (id) {

    //GET RESERVATION
    $http({method: 'GET', url: 'admin/getUpdateReservation/'+ id +'.json'}).
    success(function(data, status, headers, config) {
        $scope.post = data.data;
        var modalInstance = $modal.open({
            templateUrl: 'myModalContent.html',
            controller: 'UpdateReservationCtrl',
            resolve: {
                data: function () {
                    $scope.post.status = $scope.status;
                    $scope.post.locations = $scope.locations;
                    return $scope.post;
                }
            }
        });
        modalInstance.result.then(function (selectedItem) {
        }, function () {
            $log.info('Modal dismissed at: ' + new Date());
        });
    }).
    error(function(data, status, headers, config) {
        alert('error');
    });
};

})

我有updateReservationController.js文件。

  hansApp.controller('UpdateReservationCtrl', function ($rootScope, $scope, $route, $http, $modalInstance, data) {
console.log('6');
  })

console.log(&#39; 6&#39;);作品。但我无法看到模态页面...... 我怎样才能使我的模态作品?

1 个答案:

答案 0 :(得分:0)

所以首先,如果你没有做出承诺,就不要使用决心......

什么文档对解决方案说:Key:

  

包含将被注入的依赖项的对象   所有依赖关系都已解决后,controller的构造函数。该   如果承诺被拒绝,控制器将无法加载。

看起来你正在使用AngularStarp的模态(如果我错了,请纠正我。)

正如他们在文档中提到的那样,你必须做这样的事情:

   modal = $modal({
            controller: function($scope) {},
            show: false,
        });

并在你的成功回调中:

modal.$promise.then(modal.show);