由於過去幾個月,我一直在做很多JS,但我從來沒有真正學會了它在大學/一本書等查詢有關的setTimeout()
這裏有一個問題:
$scope.selectTab = function($index, tab) {
$scope.template = $scope.templates[$index];
$scope.data.tabSelected = tab;
setTimeout(function() {
console.clear();
console.log($scope.template);
console.log(document.getElementById("SomeDiv"))
console.log("Going to draw now...")
draw_analytics($scope); // Draw on SomeDiv
}, 0);
}
while the above code works;但下面的一個沒有。
$scope.selectTab = function($index, tab) {
$scope.template = $scope.templates[$index];
$scope.data.tabSelected = tab;
console.clear();
console.log($scope.template);
console.log(document.getElementById("SomeDiv"))
console.log("Going to draw now...")
draw_analytics($scope);
}
我使用一些黏合事情AngularJS,但這並不影響我猜。 在最上面的代碼中,當我嘗試獲取SomeDiv
dom時,我實際上得到它的HTML內容,而在底部代碼中,返回null
。
你是什麼意思'fsb'?該代碼沒有任何內容。 – Lloyd
'不起作用'是什麼意思?如果有任何錯誤,請在這裏發佈 – k102
對不起,我的意思是'SomeDiv'。那麼如果底層代碼'SomeDiv'是'null'(儘管它不應該是'$ scope.template = $ scope.templates [$ index];'將正確的HTML賦值給它)。在頂級代碼中,它會很好。 –