親コントローラーのスコープ変数は、トランスクルードされたディレクティブ スコープの関数内からどのように更新されますか?
次の方法でトランスクルージョンを使用して、ディレクティブを別のディレクティブに埋め込んでいます。
<my-table>
<my-getter-button></my-getter-button>
</my-table>
my-table と my-getter-button のコードは次のとおりです。
my-table
テンプレート:
<table>
<tr ng-repeat="item in items">
<td data-id="{{item.Id}}" ng-transclude></td>
</tr>
</table>
my-table
指令:
.directive('myTable', function () {
return {
transclude: true,
restrict: 'E',
templateUrl: 'views/mytable.html',
scope: false
};
});
my-getter-button
ディレクティブ (テンプレート付き):
app.directive('myGetterButton', function () {
function link(scope, element) {
scope.finalizeGet = function () {
var id = element.parent().data('id');
scope.clear(); // <-- works fine (from parent controller)
scope.get(id) // <-- works fine (from parent controller)
.success(function (data) {
// The line below was supposed to
// update the variables within the parent controller:
scope.$parent.instance = data; // or scope.instance = data;
angular.element('#detailsModal').modal('show');
})
.error(function (data) {
scope.errors = data;
});
};
};
return {
restrict: 'E',
template: '<button class="btn btn-info" ng-click="finalizeGet()">' +
'<span class="glyphicon glyphicon-book"></span>' +
'</button>',
scope: false,
link: link
};
});
scope.$parent.instance = data; // or scope.instance = data;
親コントローラーを変更することを期待していましたが、変更されscope.instance
ませんでした。