AngularJS模态弹出窗口

AngularJS模态弹出窗口,angularjs,twitter-bootstrap,bootstrap-modal,Angularjs,Twitter Bootstrap,Bootstrap Modal,我真的是个新手。我正在尝试在这个链接上重新创建模态示例,但我没有运气!我创建了一个plunker我只需要能够打开一个按钮点击模式。我收到错误消息error:[ng:areq]参数'ModalDemoCtrl'不是函数,未定义 这是我的看法 <div ng-controller="ModalDemoCtrl"> <script type="text/ng-template" id="myModalContent.html"> <div class="modal

我真的是个新手。我正在尝试在这个链接上重新创建模态示例,但我没有运气!我创建了一个plunker我只需要能够打开一个按钮点击模式。我收到错误消息error:[ng:areq]参数'ModalDemoCtrl'不是函数,未定义

这是我的看法

<div ng-controller="ModalDemoCtrl">
<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="open()">Open me!</button>
<button type="button" class="btn btn-default" ng-click="open('lg')">Large modal</button>
<button type="button" class="btn btn-default" ng-click="open('sm')">Small modal</button>
<button type="button" class="btn btn-default" ng-click="toggleAnimation()">Toggle Animation ({{ animationsEnabled }})</button>
<div ng-show="selected">Selection from a modal: {{ selected }}</div>
}))


您需要修复此行:

angular.module('crm.ma').controller('ModalDemoCtrl', ModalDemoCtrl, function ($scope, $uibModal, $log) {    
//  what is this, huh? ------------------------------------^
正确代码:

angular.module('crm.ma').controller('ModalDemoCtrl', function ($scope, $uibModal, $log) {

ModalInstanceCtrl
也有类似的问题

您还缺少
ng app=“crm.ma”
属性


演示:

这是一个正确的叉子:。 你只是有一些小的语法错误

JAVASCRIPT

var app = angular.module('crm.ma', ['ngAnimate', 'ui.bootstrap']);

app.controller('ModalDemoCtrl', function ($scope, $uibModal, $log) {

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

$scope.animationsEnabled = true;

$scope.open = function (size) {

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

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

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

});

// Please note that $modalInstance represents a modal window (instance)   dependency.
// It is not the same as the $uibModal service used above.

app.controller('ModalInstanceCtrl', function ($scope, $modalInstance, items) {

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

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

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


我是模态的!
选定:{{Selected.item} 好啊 取消 打开我! 大模态 小模态 切换动画({{animationEnabled}}) 从模式中选择:{{selected}
你的弹夹坏了。@PankajParkar对此表示抱歉。我把代码放在index.html文件中。您现在应该可以看到它了。您需要在
script.js
@PankajParkar之前包含
angular.js&ui bootstrap.js
。这是我应用程序的一小部分。在实际的应用程序中,它们都包括在内。我修改了代码行,但仍然不起作用。ng应用程序包含在我的实际应用程序中。这是一个巨大的应用程序,我刚刚添加了我对Plunker有疑问的页面。ReferenceError:ModalInstanceCtrl未定义(匿名函数)@ModalDemoCtrl.js:36 angular.js:68未捕获错误:[$injector:modulerr]未能实例化模块crm.ma,原因是:错误:[$injector:modulerr]未能实例化模块ngAnimate,原因是:错误:[$injector:nomod]模块“ngAnimate”不可用!您要么拼错了模块名,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。谢谢你的帮助!这是我需要添加到index.html的唯一脚本文件吗
ModalInstanceCtrl
与我在回答中解释的内容类似。您还需要模板,或者更好的0.14.0/ui-bootstrap-tpls.min.js文件。只需查看我发布的带有固定代码的演示。好的,我去了你的plunker并更改了我的代码以匹配你的代码。我已经像你一样包含了脚本文件。它仍然不起作用。我没有收到错误消息,我收到的是空白页。如果删除索引页中的引用,空白页就会消失。我更改了代码以匹配您的代码。我仍然没有收到任何错误,但是如果我将我的控制器添加到index.html页面,它返回时没有错误,并且是一个空白页面。你知道我做错了什么吗?@hollyquinn,你把它弄好了吗?对不起,我有几天没有去看医生。
angular.module('crm.ma').controller('ModalDemoCtrl', function ($scope, $uibModal, $log) {
var app = angular.module('crm.ma', ['ngAnimate', 'ui.bootstrap']);

app.controller('ModalDemoCtrl', function ($scope, $uibModal, $log) {

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

$scope.animationsEnabled = true;

$scope.open = function (size) {

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

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

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

});

// Please note that $modalInstance represents a modal window (instance)   dependency.
// It is not the same as the $uibModal service used above.

app.controller('ModalInstanceCtrl', function ($scope, $modalInstance, items) {

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

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

  $scope.cancel = function () {
    $modalInstance.dismiss('cancel');
  };
});
<!DOCTYPE html>
<html data-ng-app="crm.ma">

<head>
<link data-require="bootstrap-css@3.1.1" data-semver="3.1.1" rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="style.css" />
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.6/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.6/angular-animate.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.14.0.js"></script>
<script src="ModalDemoCtrl.js"></script>
</head>

<body>
  <div ng-controller="ModalDemoCtrl">
    <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="open()">Open me!</button>
  <button type="button" class="btn btn-default" ng-click="open('lg')">Large modal</button>
  <button type="button" class="btn btn-default" ng-click="open('sm')">Small modal</button>
  <button type="button" class="btn btn-default" ng-click="toggleAnimation()">Toggle Animation ({{ animationsEnabled }})</button>
  <div ng-show="selected">Selection from a modal: {{ selected }}</div>
  </div>
  </body>

 </html>