单击按钮

时间:2015-10-23 19:19:05

标签: angularjs twitter-bootstrap bootstrap-modal

我正在尝试做一些事情,我猜测应该相当容易,但我无法弄清楚。我想做的就是点击按钮打开一个模态。我正在关注这个例子。 http://fdietz.github.io/recipes-with-angular-js/common-user-interface-patterns/displaying-a-modal-dialog.html

这是我的控制器:

var app = angular.module("MyApp", ["ui.bootstrap.modal"]);

app.controller('MyCtrl', function ($scope) {
$scope.open = function () {
    $scope.showModal = true;
};

$scope.ok = function () {
    $scope.showModal = false;
};

$scope.cancel = function () {
    $scope.showModal = false;
};
});

以下是我的观点:

<button class="btn" ng-click="open()">Open Modal</button>

<div modal="showModal" close="cancel()">
    <div class="modal-header">
        <h4>Modal Dialog</h4>
    </div>
    <div class="modal-body">
        <p>Example paragraph with some text.</p>
    </div>
    <div class="modal-footer">
        <button class="btn btn-success" ng-click="ok()">Okay</button>
        <button class="btn" ng-click="cancel()">Cancel</button>
    </div>
</div>

我收到错误消息错误:[ng:areq]参数'MyCtrl'不是函数,未定义。并且模式在加载时显示在页面上。提前谢谢。

1 个答案:

答案 0 :(得分:2)

在第一行,您使用“modal =”。这是一个指令,您需要在代码中实现它。 (见这里:AngularJS reusable modal bootstrap directive

对于问题“Argument'MyCtrl'不是函数,未定义”,我认为这是一个依赖问题。这里有一个类似的问题:Angularjs: Error: [ng:areq] Argument 'HomeController' is not a function, got undefined

如果你想实现一个模态对话框,我建议你在这里看到官方的Bootstrap-Angular Doc:https://angular-ui.github.io/bootstrap/