내 지시문에서 ngModel을 요구하고 내 링크 함수 내에서 네 번째 인수 ngModel을 사용하면 바인딩 된 모델의 값에 액세스 할 수 있습니다. 제 경우에이 바운드 값은 product.id (ng-repeat 내부)입니다.
이제 링크 함수에서 제품 개체의 다른 값을 어떻게 읽을 수 있습니까?
<input type="hidden" ng-model="product.id" my-directive">
app.directive('myDirective', function() {
restrict: "a",
require: "ngModel",
link: function(scope, element, attrs, ngModel) {
// Here I want to read product.name, product.price etc
}
});
입력 데이터 태그로 제품을 바인딩 할 수 있습니다. 처럼:-
<input type="hidden" ng-model="product.id" data-product="product" my-directive">
app.directive('myDirective', function() {
restrict: "a",
scope{
product: "=product"
},
link: function(scope, element, attrs, ngModel) {
// Here I want to read product.name, product.price etc
//Here scope.product will return all the values
}
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다