Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.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 焦点文本区域在ng上单击_Javascript_Html_Angularjs_Angularjs Ng Repeat - Fatal编程技术网

Javascript 焦点文本区域在ng上单击

Javascript 焦点文本区域在ng上单击,javascript,html,angularjs,angularjs-ng-repeat,Javascript,Html,Angularjs,Angularjs Ng Repeat,我想单击ng repeat中的一个按钮,然后关注循环中特定项目的textarea HTML <div ng-repeat="item in items"> <textarea focus-when="showTextarea">{{ item }}</textarea> <a ng-click="trigger()" href="#">Focus</a> </div> <div ng-controller="

我想单击
ng repeat
中的一个按钮,然后关注循环中特定项目的
textarea

HTML

<div ng-repeat="item in items">
  <textarea focus-when="showTextarea">{{ item }}</textarea>
  <a ng-click="trigger()" href="#">Focus</a>
</div>
<div ng-controller="MyCtrl">
<div ng-repeat="item in items">
    <button class="btn" ng-click="showForm=true; focusInput=true">show form and focus input #{{ item }}</button>
    <div ng-show="showForm">
      <input type="text" focus-me="focusInput">
      <button class="btn" ng-click="showForm=false">hide form</button>
    </div>
  </div>
</div>
代码:

我有指令
focusWhen
,它观察了
showTextarea
范围变量。当
ng单击
trigger时,它会将此
showTextarea
更改为true,并应聚焦
textarea

然而,我的代码不起作用,它有错误

错误:[$injector:unpr]未知提供程序:$scopeProvider更改

app.directive('focusWhen', function($scope) {


是的,我犯了错误,但我只是把问题分开,仍然在上面的
#2
上寻找答案。
var app = angular.module('plunker', []);
var MyCtrl = function ($scope, $timeout) {
  $scope.items = [1,2,3];
};

app.directive('focusMe', function($timeout) {
  return {
    scope: { trigger: '=focusMe' },
    link: function(scope, element) {
      scope.$watch('trigger', function(value) {
        if(value === true) { 
          //console.log('trigger',value);
          //$timeout(function() {
            element[0].focus();
            scope.trigger = false;
          //});
        }
      });
    }
  };
});
app.directive('focusWhen', function($scope) {
app.directive('focusWhen', function() {