JQueryを使用するもう1つの提案。 ディレクティブで生成されたグリッドに対して、これを実行する必要がありました。私はグリッド内の特定の行にスクロールしたかったのです。ディレクティブで
['$timeout',function($timeout){
...
$scope.$on('dataloaded', function() {
$timeout(function() { // You might need this timeout to be sure its run after DOM render.
$scope.scrollToPosition();
}, 0, false);
});
$scope.scrollToPosition = function() {
var rowpos = $('#row_' + $scope.selectedActionID, "#runGrid").position();
var tablepost = $('table', "#runGrid").position();
$('#runGrid').scrollTop(rowpos.top - tablepost.top);
}
.directive('runGrid',['$timeout', function ($timeout) {
// This directive generates the grip of data
return {
restrict: 'E', //DOM Element
scope: { //define isolated scope
list: '=', //use the parent object
selected: "="
},
templateUrl: '/CampaignFlow/StaticContent/Runs/run.grid.0.0.0.0.htm', //HTML template URL
controller: ['$scope', function ($scope) { //the directive private controller, whith its private scope
//$scope.statusList = [{ data_1: 11, data_2: 12 }, { data_1: 21, data_2: 22 }, { data_1: 31, data_2: 32 }];
//Controller contains sort functionallity
$scope.sort = { column: null, direction: 1 }
$scope.column = null;
$scope.direction = "asc";
$scope.sortColumn = function (id) {
if(id!=$scope.column) {
$scope.column = id;
$scope.direction = "asc";
} else {
$scope.column = null;
}
}
$scope.toggleDir = function() {
$scope.direction = ($scope.direction == "asc") ? "desc" : "asc";
}
$scope.$emit('dataloaded');
}]
};
}])
そして、これは、グリッドディレクティブHTMLテンプレートの抜粋です:コントローラで
:$親コントローラに指令から放送するために発する使用
<div style="overflow-y:auto;height: 200px;" id="runGrid">
<table class="table table-striped" style="table-layout:fixed">
<tbody>
<tr ng-repeat="status in list" id="row_{{status.action_id}}" ng-class="(status.action_id==selected)?'selected':''">
<td>
リストと選択されたパラメータが、direを使用しているhtmlから注入されますctive
<run-grid list="list" selected="selectedActionID"></run-grid>
をダイジェスト発生させずに$タイムアウトの使用方法へのリンクがdrzausします。ちょうど同じように。予期せぬ$ compile呼び出し、任意の数のディレクティブ、DOM自身を操作して$タイムアウトの後に行う設定をすることがあります... AngularJSシステムは美しく設計されているので、断片は独立して動作します。支払う。ちょうど別の方法を見つける。 – rewritten
とにかくできると思います。私は、その命令でdomがコンパイル関数を呼び出すことができる、または予測できない他の何かがそれを防ぐことができないという事実、imhoを意味します。 – Dobby007
古い質問を人生に持ち込んで申し訳ありませんが、#wrapperのコンテンツを共有できますか?おそらく、取引を繰り返すだけでしょうか? – FrEaKmAn