Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 除了$timeout之外,还有什么方法可以让第二个摘要在angular中运行吗?_Angularjs_Angularjs Digest - Fatal编程技术网

Angularjs 除了$timeout之外,还有什么方法可以让第二个摘要在angular中运行吗?

Angularjs 除了$timeout之外,还有什么方法可以让第二个摘要在angular中运行吗?,angularjs,angularjs-digest,Angularjs,Angularjs Digest,我正在编写一个属性指令,其中如果设置了一个变量,它会将禁用的属性添加到所有输入和按钮中,本质上使表单成为只读的。这是一个功能请求。。。该表单用于过期数据,但如果需要,客户机希望查看该表单 无论如何,我在视图上有一些输入和按钮,还有一些我编写的自定义指令,其中包含输入、选择和按钮。出于某种原因,无论怎样,我都无法将正在处理的attribute指令用于.find()自定义指令中的输入和选择,除非我对.find()使用$timeout。这是我到目前为止所拥有的。这是可行的,但我知道我的同事会拒绝使用$

我正在编写一个属性指令,其中如果设置了一个变量,它会将禁用的属性添加到所有输入和按钮中,本质上使表单成为只读的。这是一个功能请求。。。该表单用于过期数据,但如果需要,客户机希望查看该表单

无论如何,我在视图上有一些输入和按钮,还有一些我编写的自定义指令,其中包含输入、选择和按钮。出于某种原因,无论怎样,我都无法将正在处理的attribute指令用于.find()自定义指令中的输入和选择,除非我对.find()使用$timeout。这是我到目前为止所拥有的。这是可行的,但我知道我的同事会拒绝使用$timeout

'use strict';
angular.module('induction').directive('sttiDisabled',['$timeout', function($timeout) {
    return {
        restrict: 'A',
        link: function postLink(scope, elem, attrs) {
            var hello = function () {
                var formControls = angular.element(elem.querySelectorAll('input, select, button'));
                for (var i = 0; i < formControls.length; i++) {
                    var el = angular.element(formControls[i]);
                    el.attr('disabled', scope.ceremony.locked);
                    console.log(el);
                };
            };

            // Don't judge. It works flawlessly.
            var promise = $timeout(hello, 0);


        }
    }
}]);
“严格使用”;
角度.module('inclusion')。指令('sttiDisabled',['$timeout',函数($timeout){
返回{
限制:“A”,
链接:函数postLink(范围、元素、属性){
var hello=函数(){
var formControls=angular.element(elem.querySelectorAll('input,select,button');
对于(var i=0;i
您可以这样使用它:

<div stti-disabled>
<input ng-model="blah" />
<select ng-model="blah2" />
<custom-directive-containing-an-input> </that>
</div>

如果scope.certium.locked==true,则将禁用输入和选择,但不会禁用自定义指令中的输入。。。除非我使用超时

编辑:可能是重复,但我想再次提出这个问题,因为自2014年以来情况可能发生了变化。

Update 要禁用组中的所有输入,请将与一起使用:

有关作用域方法的更多信息,请参阅

更新

您使用
$timeout
连续调用“hello”方法的方法无法完美地运行;它脆弱地工作。如果在应用程序中添加更多的
$timeout
s,会发生什么情况?您无法保证调用函数的顺序


通过使用
$watch
,您可以保证在感兴趣的范围变量初始化和更改时调用“hello”函数。

riture.locked不会立即更改。在你读到任何一页之前就已经设定好了。。仪式是一个根镜对象。当我希望用户无法编辑表单时,我向其添加locked=true。我很肯定这只手表永远不会着火,但我会试试看。
<fieldset ng-disabled="formDisable">
   <input ng-model="blah" />
   <select ng-model="blah2" 
          ng-options="name for name in [1,2,3]">
   </select>
   <custom-directive-containing-an-input> 
   </custom-directive-containing-an-input>
   <br>input = {{blah}}
   <br>select = {{blah2}}
   <br>disable = {{formDisable}}
</fieldset>
<input type=checkbox ng-model="formDisable"/>Disable form
  scope.$watch("ceremony.locked", hello);