이에 대한 속성 값으로 함수 호출 내 지시어의 감소이다 :각도 : 지시어
app.directive('myDirective', function() {
return {
restrict: 'E',
replace: true,
template:
'<form name="form" action="{{action}}" method="post" target="_blank">' +
'<input type="hidden" name="item_name" value="{{itemname}}">' +
'</form>',
scope: {
action: '@action',
itemname: '@itemname',
},
link: function(scope, element, attrs) {
scope.action = attrs.action || 'http://www.example.com';
scope.itemname = attrs.itemname();
}
};
});
와 나는이 방법을 사용
$scope.itemNameBuildFunction = function() {
return $scope.value1 + $scope.value2;
};
내 지침이 연결될 때 예상됩니다 (ng-if
절 안에 있으므로 ng-if
조건이 true로 평가됨) attrs.itemname()
$ scope 함수를 호출하여 컨트롤러의 링크 함수에서 scope.itemname 변수를 할당합니다.
TypeError: attrs.itemname is not a function
당신이 나에게 몇 가지 지시 사항을 적어주세요 수 :
대신, 내가 무엇을 얻을하면 오류가 무엇입니까? 당신이 볼 수 있듯이, 나는 당신이 문 attrs.itemname()
필요하지 않습니다 :-(...
my-directive> 지시문을 닫고 scope.itemname = attrs.itemname도 시도해 보았습니까? –
이 함수는'attrs.itemname()'무엇입니까? 결코 정의 된 것을 보지 못했습니다 ... 또한 함수로 정의 된 경우 attrs가 JSON 객체로 변환합니다. 그래서 angular.fromJson (attrs.itemname) – Zargold
@MandeepSingh를 사용해야합니다 : 첫 번째 조언 : 감사, 그냥 내 대답을 수정; 두 번째 조언 : 그 방법으로, 생산 된 형태로 나는'itemname'이라는 문자열을 얻을 것이다. 기대하지 않는 것은 ... :-( – MarcoS