0
私はAngularJSで新しく、ディレクティブのものと少し混乱しています。 以下のコードでは、アウトソースモジュールにあるディレクティブで入力フィールドを作成し、カスタムディレクティブでそれに焦点を当てる必要があります。
...anglejsのメインモジュールからモジュールの後にディレクティブをトリガーする方法
myHtml.html
<body ng-app="main" ng-controller="myCtrl">
<my-field></my-field>
</body>
Outsource.js
var app2 = angular.module('pain', []);
app2.directive('myField', [function() {
return {
scope.f = 'focus-me';
},
template: 'name: <input type="text" class="{{f}}"/>' +
'<br/>' +
'input class is: \"{{f}}\"'
}
}]);
myApp.js
私はアウトソースモジュールを変更することはできませんように注意してくださいvar app1 = angular.module('main', ['pain']);
app1.controller('myCtrl', ['$scope', function($scope) {
$scope.state = true;
}]);
app1.directive('focusMe', ['$timeout', '$parse', function($timeout, $parse) {
return {
restrict: 'C',
link: function(scope, element) {
scope.$watch(scope.state, function() {
console.log('value=', scope.state);
if (scope.state === true) {
$timeout(function() {
element[0].focus();
}, 20);
}
});
}
};
}]);
フィドル
fiddler
なお、以下に、このようなコードでOKでしょうが、私はアウトソースコードを変更することはできません。
それはあなたがよっぽどあなたが仕事にやりたいことのためにOutsource.jsにコードを修正する必要が
fiddler