I have some content on my page which is wrapped in an ng-if like below:
<div ng-if="ShowMessgae" class="text-danger">
<p>
<strong>
Message displayed to User
</strong>
</p>
</div>
Then in my angular js controller I have the following:
function MyController($scope, $q, notifyHelper) {
openAjaxLoaderGif();
$scope.ShowMessgae = false;
MyService.getVarsFromSession().then(function (result) {
// some code removed for brevity
if(some coditional) {
$scope.ShowMessgae = true;
}
}, function (data, failReason, headers) {
notifyHelper.error("Error has occurred - try again");
})
})
.finally(function () {
closeAjaxLoaderGif();
});
};
I am setting the value of ShowMessage to false and it only is true if a certain condition is met. In the majority of instances ShowMessage will be false. However this results in when the page loads the markup Message displayed to User briefly renders and then it disappears (to show what I expect) - is there something I am doing wrong which is causing this flicker?
add
ng-cloak
like belowThis is because the content is rendered untils angular detects that
ShowMessgae
isfalse
and then hides it.In order to not show the content at all until angular is ready to "say" whether
ShowMessgae
istrue
orfalse
you should useng-cloak
. This way the content is not shown until angular "knows" the value ofShowMessgae
. Then, at this point, angular is ready to show (or not) the content, depending on the value ofShowMessgae