显示控制器angular js的模态
Displaying the modal from the controller angular js
我是angular js的新手,正在尝试使用angular jss创建一个简单的模态。以下是我的模式代码
<div id="sampleModal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Sample Modal</h4>
</div>
<div class="modal-body">
<div class="form-group">
<h5>Name</h5>
<input type="text" class="form-control" id="name" placeholder="Enter a name">
</div>
<div class="form-group">
<div style="text-align:center;">
<button type="submit" class="btn btn-primary btn-sm">Submit</button>
<button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
</div>
</div>
点击下面的按钮调用上述模式
<button class="btn btn-primary" type="button" id="modal" ng-click="create()">Create</button>
我的控制器如下
var App = angular.module('myApp', []);
App.controller('homeCtrl', ['$scope',function($scope,) {
$scope.create = function() {
//code to show the modal
}
}]);
我应该如何编写我的create函数来显示模态。我看过很多教程,但找不到一种方法让它发挥作用。
谢谢。
查看Angular UI引导程序。它有很好的模态支持和一个示例来帮助您。
https://angular-ui.github.io/bootstrap/#/modal
步骤1:直接打开模态,不与控制器交互。
<button class="btn btn-info btn-sm" data-toggle="modal" data-target="#sampleModal">Create
</button>
步骤2:与控制器交互。
<button class="btn btn-primary" type="button" ng-click="create()">Create</button>
var App = angular.module('myApp', []); App.controller('homeCtrl', ['$scope',function($scope,) {
$scope.create = function() {
angular.element('#sampleModal').modal('show');
}
}]);
N.B:模态应为bootstrap
。并且CCD_ 2必须在项目中加载。
相关文章:
- 有没有比在app.js上绑定模块名称更好的方法来动态加载视图模型和视图以显示模态
- jqueryajax调用是复制url,当在模态视图之后在外部js文件中进行调用时
- React.js中显示了模态时如何执行某些操作
- Angular Js 尝试从主按钮回调动态更改模态文本并且不起作用
- Angular js - 异步调用 $scope.users 后不更新模态值
- 理解模态.js中复杂的 $.extend
- setScrollbar() 方法实际上在模态.js中做什么
- 如何在模态助推器中显示计算结果(JS)
- 在模态中使用 e.target 的复杂 if 条件.js
- 创建一个模态指令,并将click事件绑定到angular js中
- 当使用angular.js和ui.bootstrap时,从模态内部的按钮单击事件未触发
- 显示控制器angular js的模态
- 如何在使用模态的同时使用AJAX在js和php之间进行通信
- $scope在模态角 js 中未定义
- 角度JS.超时模态隐藏在已打开的模态后面
- 模态对话框加载 jquery 在控制台中执行,但不从应用程序加载.js
- Angular JS将msg广播到多个视图,包括模态窗口
- 无法从模态元素 Angular JS 获取$file
- 电子表格中的单个动态模态/ JS(而不是每个单元格一个)
- 使用按钮在任何站点上显示模态JS对话框