2015-09-18 2 views
0

Я использую угловую щ-bootsrap модальность из hereИспользование UI-самозагрузки режимные

При нажатии на кнопку Open me я ничего не получаю. Всплывающее окно не отображается. Мой код можно найти ниже.

app.js

(function() { 

     'use strict'; 
     angular.module('probaApp', ['ui.router','ngAnimate','ui.bootstrap','ui.bootstrap.modal']) 
      .config(function ($stateProvider, $urlRouterProvider) { 

       $urlRouterProvider.otherwise("/home"); 

       $stateProvider 
        .state('home', { 
         url: '/home', 
         templateUrl: 'src/home.tpl.html', 
         controller: 'modalController' 
        }) 

      }); 
    })(); 

index.html

<!DOCTYPE html> 
<html lang="en" ng-app="probaApp"> 
<head> 
    <meta charset="UTF-8"> 
    <link type="text/css" rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css"> 
    <title></title> 
</head> 
<body> 

<ui-view></ui-view> 

<script src="bower_components/angular/angular.js"></script> 
<script src="bower_components/angular-bootstrap/ui-bootstrap.js"></script> 
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script> 
<script src="bower_components/angular-animate/angular-animate.js"></script> 
<script src="src/app.js"></script> 
<script src="src/modal-controller.js"></script> 
<script src="src/modal-instance-controller.js"></script> 

</body> 
</html> 

модальные-controller.js

 (function() { 
    'use strict'; 

    function ModalController($scope,$modal,$log) { 

     $scope.modalController = {}; 

     $scope.modalController.items = ['item1', 'item2', 'item3']; 

     $scope.modalController.animationsEnabled = true; 

     $scope.modalController.open = function(size){ 

      $scope.modalController.modalInstance = $modal.open({ 
       animation: $scope.animationsEnabled, 
       templateUrl: 'myModalContent.html', 
       controller: 'modalInstanceController', 
       size: size, 
       resolve: { 
        items: function() { 
         return $scope.modalController.items; 
        } 
       } 
      }); 

      $scope.modalController.result.then(function (selectedItem){ 
       $scope.modalController.selected = selectedItem; 
      },function(){ 
       $log.info("Modal dismissed at: " + new Date()); 
      }); 

     }; 

     $scope.modalController.toggleAnimation = function(){ 
      $scope.modalController.animationsEnabled = !$scope.modalController.animationsEnabled; 
     }; 


    } 

    angular.module('probaApp').controller('modalController', ModalController); 
})(); 

Модальные-Instance-контроллер

/** 
* Created by user on 19.09.2015. 
*/ 
(function(){ 

    function ModalInstanceController ($scope,$modalInstance,items){ 

     $scope.modalInstanceController = {}; 

     $scope.modalInstanceController.items = items; 
     $scope.modalInstanceController.selected = { 
      item: $scope.items[0] 
     }; 

     $scope.modalInstanceController.ok = function(){ 
      $modalInstance.close($scope.modalInstanceController.selected.item); 
     }; 

     $scope.cancel = function(){ 
      $modalInstance.dismiss('cancel'); 
     } 
    } 

    angular.module('probaApp').controller('modalInstanceController',ModalInstanceController); 
})(); 

home.tpl

<div> 
    <script type="text/ng-template" id="myModalContent.html"> 
     <div class="modal-header"> 
      <h3 class="modal-title">I'm a modal!</h3> 
     </div> 
     <div class="modal-body"> 
      <ul> 
       <li ng-repeat="item in items"> 
        <a href="#" ng-click="$event.preventDefault(); selected.item = item">{{ item }}</a> 
       </li> 
      </ul> 
      Selected: <b>{{ selected.item }}</b> 
     </div> 
     <div class="modal-footer"> 
      <button class="btn btn-primary" type="button" ng-click="ok()">OK</button> 
      <button class="btn btn-warning" type="button" ng-click="cancel()">Cancel</button> 
     </div> 
    </script> 

    <button type="button" class="btn btn-default" ng-click="modalController.open()">Open me!</button> 
</div> 

EDIT для бешеной

TypeError: Cannot read property 'then' of undefined 
    at Object.ModalController.$scope.modalController.open (http://localhost:63342/Proba/src/modal-controller.js:26:42) 
    at fn (eval at <anonymous> (http://localhost:63342/Proba/bower_components/angular/angular.js:13275:15), <anonymous>:4:293) 
    at callback (http://localhost:63342/Proba/bower_components/angular/angular.js:23481:17) 
    at Scope.$eval (http://localhost:63342/Proba/bower_components/angular/angular.js:15922:28) 
    at Scope.$apply (http://localhost:63342/Proba/bower_components/angular/angular.js:16022:25) 
    at HTMLButtonElement.<anonymous> (http://localhost:63342/Proba/bower_components/angular/angular.js:23486:23) 
    at HTMLButtonElement.eventHandler (http://localhost:63342/Proba/bower_components/angular/angular.js:3296:21)(anonymous function) @ angular.js:12450(anonymous function) @ angular.js:9237Scope.$apply @ angular.js:16027(anonymous function) @ angular.js:23486eventHandler @ angular.js:3296 
angular.js:12450 TypeError: Cannot read property '0' of undefined 
    at new ModalInstanceController (modal-instance-controller.js:12) 
    at invoke (angular.js:4476) 
    at Object.instantiate (angular.js:4484) 
    at angular.js:9142 
    at resolveSuccess (ui-bootstrap-tpls.js:2983) 
    at processQueue (angular.js:14678) 
    at angular.js:14694 
    at Scope.$eval (angular.js:15922) 
    at Scope.$digest (angular.js:15733) 
    at Scope.$apply (angular.js:16030) 
+0

$ scope.modalController не имеет «результата» свойства, $ scope.modalController.modalInstance имеет свойство «результат». Вот почему вы получаете эту ошибку. – o4ohel

+0

tnx man первая ошибка исчезла, но вторая ошибка: TypeError: Can not read property '0' undefined все еще там ... – Bukic

ответ

1

Это потому, что вы делаете «$ scope.modalController.result ...», которого не существует. Вам нужно сделать «$ scope.modalController.modalInstance.result.then ...»

Кроме того, я не уверен, почему вы вводите переменную scope «modalController»? Это не нужно и просто добавляет путаницу.

+0

tnx man первая ошибка исчезла, но вторая ошибка: TypeError: Невозможно прочитать свойство '0' неопределенного все еще там ... – Bukic

+0

эй, мужчина, ты знаешь, жарко, чтобы сделать этот модальный перетаскиваемый? – Bukic

+0

У меня не было необходимости, но есть несколько примеров ... вот что: http://embed.plnkr.co/8CHoiN/preview – o4ohel

0

У меня аналогичная проблема с модальным. Я думаю, что это проблема css и даже связана с вещью z-index. Интересно, есть ли какое-то свойство css из библиотеки начальной загрузки, которая скрывает родительский элемент.

0

Таким образом, модальный не открывается по многим причинам. Подобно o4ohel сказал пропавший свойство «результат». Тогда вам нужно дать размер. Я предпочитаю прокомментировать критические вещи и попытаюсь открыть только пустое модальное выражение «привет». Как только вы достигнете этого, вы идете дальше

0

Хорошо, поэтому я нашел ошибки. Первый: $ scope.modalController.result ==> $ scope.modalController.modalInstance.result Second one was: item: $ scope.items [0] item: $ scope.modalInstanceController.items [0].

Как o4ohel сказал, может быть я не должен использовать уаг modalController ....

Смежные вопросы