Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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
Javascript 为什么可以';我不能在选择元素上使用角度指令吗?_Javascript_Angularjs_Onfocus - Fatal编程技术网

Javascript 为什么可以';我不能在选择元素上使用角度指令吗?

Javascript 为什么可以';我不能在选择元素上使用角度指令吗?,javascript,angularjs,onfocus,Javascript,Angularjs,Onfocus,我有一个指令来关注我的应用程序中的字段 关注指令 module.exports = function() { return function(scope, elem, attr) { debugger; scope.$on('focusOn', function(e, name) { if (name === attr.focusOn) { elem[0].focus(); }

我有一个指令来关注我的应用程序中的字段

关注指令

module.exports = function() {
    return function(scope, elem, attr) {
      debugger;
        scope.$on('focusOn', function(e, name) {
            if (name === attr.focusOn) {
                elem[0].focus();
            }
        });
    };
};
它在这个输入字段上工作:

<input type="text" focus-on="diameter" />
但当我尝试在中的选择元素上执行相同操作时,不起作用:

<select focus-on="type"
        tabindex="{{item.layerId}}"
        ng-options="materialType.id for materialType in presetData.materialTypes track by materialType.id"
        ng-model="item.type"
        ng-change="materialTypeChanged(item.type)">
</select>


为什么它不能在我的select元素上工作

这是一种奇怪的定义指令()的方法,您从哪里了解到的?它应该只工作一次,就像您所做的那样
$rootScope.$broadcast('focusOn',field)仅1次。这是一种奇怪的定义指令()的方法。您从哪里了解到的?它应该只工作一次,就像您所做的那样
$rootScope.$broadcast('focusOn',field)仅1次。
<select focus-on="type"
        tabindex="{{item.layerId}}"
        ng-options="materialType.id for materialType in presetData.materialTypes track by materialType.id"
        ng-model="item.type"
        ng-change="materialTypeChanged(item.type)">
</select>