简体   繁体   English

AngularJS UI-Bootstrap模态

[英]AngularJS UI-Bootstrap Modal

Below is my angular code I am not getting any errors, the model opens up but the ModalInstanceCtrl functions cancel() and ok() do not want to work, however If I right out the controller exactly like they have it on angularjs ui-bootstrap ( http://angular-ui.github.io/bootstrap/#/modal ) directives website it seems to work. 下面是我的角度代码,我没有收到任何错误,该模型打开了,但是ModalInstanceCtrl函数cancel()和ok()不想工作,但是,如果我像正确地将控制器放在angularjs ui-bootstrap上一样将其拔出, ( http://angular-ui.github.io/bootstrap/#/modal )指令网站似乎有效。

I am using the same HTML as in the example on the website except I have extracted the inline template to its own file, which is working. 除了将内联模板提取到其自己的文件(正在运行)之外,我使用的网站示例中的HTML与该示例相同。

Package versions: Bootstrap 3.1.1, AngularJS 1.2.18, UI Bootstrap 0.11.0 软件包版本:Bootstrap 3.1.1,AngularJS 1.2.18,UI Bootstrap 0.11.0

I think the issue is here where I include the controller maybe I am not doing it correctly 我认为问题出在这里,其中包括控制器,也许我没有正确执行

controller: this.ModalInstanceCtrl,

Main App app.js: 主应用程序app.js:

'use strict'

angular.module('myApp', ['ui.bootstrap', myAppControllers]);

Controllers controllers.js: 控制器controllers.js:

'use strict';

var myApp = angular.module('myAppControllers', []);

myApp.controller('ModalCtrl', ['$scope', '$modal', '$log', function($scope, $modal, $log) {


    $scope.open = function (size) {

        var modalInstance = $modal.open({
            templateUrl: 'templates/myModalContent.html',
            controller: this.ModalInstanceCtrl,
            size: size,

           }
        });

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

myApp.controller('ModalInstanceCtrl', ['$scope', '$modalInstance', function($scope, $modalInstance) {

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

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

Ok found a solution here: 确定在这里找到了解决方案:

Calling another controller within AngularJS UI Bootstrap Modal 在AngularJS UI Bootstrap Modal中调用另一个控制器

problem is the called controller must be wrapped in single quotes: 问题是被调用的控制器必须用单引号引起来:

controller: 'ModalInstanceCtrl',

credit to Chris Southam 归功于Chris Southam

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM