我需要angularjs一個小的幫助, 請對這個 代碼(Chrome瀏覽器)來看看:如何強制角度從自定義指令渲染外部元素?
http://jsfiddle.net/Aravind00kumar/CrJn3/
<div ng-controller="mainCtrl">
<ul id="names">
<li ng-repeat="item in Items track by $index">{{item.name}} </li>
</ul>
<ak-test items="Items">
</ak-test>
</br>
<div id="result">
</div>
</div>
var app = angular.module("app",[]);
app.controller("mainCtrl",["$scope",function($scope){
$scope.Items = [
{name:"Aravind",company:"foo"},
{name:"Andy",company:"ts"},
{name:"Lori",company:"ts"},
{name:"Royce",company:"ts"},
];
$scope.Title = "Main";
}]);
app.directive("akTest",["$compile",function($compile){
return {
restrict: 'E',
replace: true,
scope: {
items: "="
},
link: function (scope, element, attrs) {
// var e =$compile('<li ng-repeat="item in Items track by $index">{{item.name}} </li>')(scope);
// $("#names").append(e);
var lilength = $("#names li").length;
var html ='<div> from angular ak-test directive: '+lilength+'</div>';
element.replaceWith(html);
}
};
}]);
$(function(){
$("#result").html('from jquery: '+$("#names li").length);
});
我創建了一個自定義的指令,並試圖從訪問一個元素在ng-repeat裏面查看我的自定義指令 問題是,在指令中它說ng-repeat還沒有呈現。 這是問題所在 我有兩個元素
<svg>
<g>
List of elements
</g>
<g>
Based on the above rendered elements I have to draw a line between elements like a connection. I have to wait till the above elements to get render then only I can read the x,y positions and can draw a line.
</g>
</svg>
兩個元件和連接是範圍變量。根據我的理解,兩者都在相同的範圍內,執行流程從父母到孩子,從孩子到父母完成。在啓動自定義指令之前,我如何強制上面的重複渲染部分完成?
有沒有其他角度可用來解決這種依賴關係?
謝謝勞斯萊斯!+1 – Aravind00Kumar