I tried calling ng-show by editing the scope in the setTimeout function. setTimeout here is a placeholder for the database query callback.
index.html
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script src="script.js"></script>
<div ng-controller="c1">
<div ng-show="{{show}}" >
test it
</div>
</div>
script.js
var amTestNgShow = angular.module('amTestNgShow',[]);
amTestNgShow.controller('c1', ['$scope', function($scope) {
setTimeout(function(){
$scope.show = true;
}, 1000)
}]);
how can this be done in setTimeout? THX!
http://plnkr.co/edit/RPS2vZAlVfhliQKteSSK
Update. As explained above, setTimeout is not a problem, it is only used to create a reproducible stack question. In my project, I created a service:
amProject1.service('asBasic', ['$http', '$q', function($http, $q){
var asBasic = {};
asBasic.docName = '';
var doc = {};
asBasic.get = function(id){
var deferred = $q.defer();
$http({method:'GET', url: '/' + this.docName + '/' + id})
.success(function(data, status, headers, config){
if(data === undefined){
deferred.reject("The requested " + asBasic.docName + " was not found.")
}
doc = data;
deferred.resolve(doc);
})
.error(function(data, status, headers, config){
deferred.reject(status);
})
return deferred.promise;
}
return asBasic;
}]);
use it like
amProject1.controller('acDoc1', ['$scope', '$routeParams', 'asBasic', function($scope, $routeParams, asBasic){
asBasic.docName = 'doc1';
asBasic.get($routeParams._id)
.then(function(data){
$scope.doc1 = data;
$scope.show = true;
}