A $ izle hepsi asenkron çünkü biz zamanlama güvenemez, burada ihtiyaç duyulan: bu nesne bir başvuru kullandığı için
myApp.controller('navCtrl', ['$state', '$scope','$timeout', function($state, $scope, $timeout){
$scope.currState = $state;
console.log("This one have some objects: ");
console.log('by reference:', $scope.currState);
console.log('by value:', JSON.parse(JSON.stringify($scope.currState)));
// console.log("But when I want to access name its empty: ");
// $timeout(function() {
// console.log($state.current.name);
// });
// use this instead:
$scope.$watch('currState.current.name', function(newValue, oldValue) {
console.log(newValue);
});
}]);
console.log('by reference:', $scope.currState);
çalışır. Konsolda gördüğümüz zaman, nesne zaten değişti.
Çıktısını çalışma noktasında donatan, yukarıdaki console.log('by value:', JSON.parse(JSON.stringify($scope.currState)));
çıkışıyla karşılaştırın. Boş bir $state.current.name
bulacaksınız.
Ayrıca bakınız: How can I change the default behavior of console.log? (*Error console in safari, no add-on*) bu konuda
Maalesef "Burada kodunu girin" Onu missclicked ve şimdi benim yazı düzenleyemezsiniz. – Arth
Plunker'da önizlemeyi ayrı bir pencerede başlatır ve bir çekicilik gibi çalışır. :) –
@Arth sorun nedir, konsolda '$ state.current.name' görüyor musunuz? –