背景: AngularJS のディレクティブのコード内で何かが発生したときに、コールバックを実行しようとしています。
関連コード:
HTML:
<img-cropper onselect="updateAvatarData" x="100" y="100" src="{{tempAvatar}}" id="avatarCropper"/>
コントローラ:
$scope.updateAvatarData = function(c){
alert("¡¡¡Funciona!!!!");
};
指令:
<<more code up here>>
link: function(scope,element, attr) {
scope.wsId = attr.id+'WS';
scope.pvId = attr.id+'preview';
scope.x = attr.x;
scope.y = attr.y;
scope.aspectRatio = scope.x/scope.y;
scope.previewStyle = "width:"+scope.x+"px;height:"+scope.y+"px;overflow:hidden;";
scope.onSelectFn = scope.$eval(attr.onselect);
<<more code down here>>
問題は、最後の行「scope.onSelectFn = scope.$eval(attr.onselect);」にあります。その「scope.$eval(attr.onselect);」「未定義」を返します。attr.onselect は正常に動作し、「onselect」属性で入力された関数の名前を返します。
問題なく属性を介して渡される関数を使用して他のディレクティブを作成しましたが、ここで間違っていることを見つけることができません。
- 前もって感謝します