我有一个模态的奇怪问题.它应该是一个绝对正常的模式,我可以打开和关闭很多次,但我可以打开一个,也只是关闭一次!http://plnkr.co/ksTy0HdifAJDhDf4jcNr
我的index.html文件看起来像这样:
<body ng-controller="MainCtrl">
<div ng-include src="'widget.html'" ng-controller="WidgetCtrl"></div>
<!-- other widgets and content -->
</body>
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我已将我的应用程序分配到不同的部分(称为小部件),我在我的索引html文件中包含了每个ng-include.每个小部件都有自己的控制器.
该widget.html看起来是这样的:
<div modal="theModal">
<div class="modal-header"><h3>The Modal</h3></div>
<div class="modal-body">
Body intentionally left blank
</div>
<div class="modal-footer">
<button class="btn" type="button" ng-click="CloseModal()">ok</button>
</div>
</div>
<!-- more modals and other stuff -->
<button ng-click="OpenModal()">open modal</button>
Run Code Online (Sandbox Code Playgroud)
现在是widget控件(它是主控制器的子控制器)
app.controller('WidgetCtrl', function ($scope) {
$scope.OpenModal = function() { $scope.theModal = true; }
$scope.CloseModal = function() { $scope.theModal = false;}
});
Run Code Online (Sandbox Code Playgroud)
用于打开和关闭模态的所有内容都是子控制器(WidgetCtrl)的一部分,因此不应与父控制器中的任何内容冲突.
$scope.theModal在开头undefined,所以模态没有显示.点击按钮$scope.theModal定义并设置为 …
我的问题是创建一个角度指令.
我想用一个单一的ng模型创建一组复选框.它就像一个位域或标志,即复选框的值从0,1,2,3到n,但对于ng-model,我只想添加所有选中复选框的2 ^值.要添加的值是1,2,4,8,16 ......
我想知道我的问题是否有更好,更正确或更简单的解决方案.
http://plnkr.co/edit/9h7EkEpDohXTniIDHdc5
在示例中,您可以更改文本框中的值,并且将更新检查,但不会更新.这有点疯狂,代码正在我的开发机器上工作,但不在Plnkr!
app.directive('ngCheckboxFlags', function () {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, element, attrs, ctrls) {
var flagSum;
var checkboxes = [];
// trigger changes of the ngModel
scope.$watch(attrs.ngModel, function (value) {
flagSum = value;
for (var i = 0, ii = checkboxes.length; i < ii; ++i) {
var checkbox = checkboxes[i];
checkbox.checked = flagSum & (1<<checkbox.value);
}
});
for (var i = 0, inputs = element.find('input[type=checkbox]'), ii = inputs.length; i < …Run Code Online (Sandbox Code Playgroud)