두 개의 입력 인 input_1 및 input_2가 있습니다. input_1에 값을 입력하고 input_2에 입력 할 때 액세스하려고합니다 (자동 완성 input_2에 대해 input_1 값 사용).지시어에서 현재 AngularJS 모델의 현재 값에 액세스하는 방법
제작 한 지침 :
.directive('autoComplete', function($timeout) {
return function(scope, inputElement, inputAttrs) {
inputElement.autocomplete({
source: (function(){
var new_list = scope[inputAttrs.uiItems];
new_list.push(scope['input_one_value']);
return new_list
})(),
select: function() {
$timeout(function() {
inputElement.trigger('input');
}, 0);
}
});
};
});
하지만이 모델의 초기 값에 액세스 할 수 있습니다 지침 내에서이 방법
. 첫 번째 입력의 현재 값에 어떻게 액세스 할 수 있습니까? 당신의 지침 내에서 모델링 할 그런<some-tag model="model"></some-tag>
사용자가 액세스 할 :
.directive('something', function() {
return {
require: ['model'],
scope: {
'model': '=', // Two way data binding
}
};
})
그리고 템플릿
이 같은 입력 1 값을 전달 :
비 - 위젯을 사용하는 것은 단지 상처의 세계를 요구하는 것입니다. 또한 바퀴벌레를 재발견하는 이유는 다음과 같은 Angular 자동 완성 위젯입니다. https://github.com/EnzeyNet/AutoComplete – Enzey
그래,하지만 AngularJS에 익숙하지 않고 '바닐라'로 사용하고 싶었습니다. 가능한 한. 그냥 플러그인을 많이 사용하기 전에 몇 가지 경험을 얻으려면 등 – Paul