I believe everyone will encounter this problem when writing angularjs, but it is not obvious in general web. When writing a wap page, it will be obvious that there is a placeholder that will stop when the interface is just opened, and then wait for the js to be asynchronous. After refreshing, the value changes again, and the experience is not very good.
I think there should be a more mature solution for this, please give me some advice~!
@Broooooklyn Following this hint, I found a very good post on stackoverflow with a very clear explanation
ng-bind or ng-cloak, the official has said it many times, using css to solve it is the best and perfect
http://www.cnblogs.com/whitewolf/p/3495822.html
https://docs.angularjs.org/api/ng/directive/ngCloak
[ng:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
display: none !important;
}
Please use ng-bind
angularjs will automatically cooperate with $qProvider, which is actually the underlying $digest loop.
Option 1
When the reject or resolve of $q's promise is not executed, the attempt will not be rendered, let alone the problem of primary placeholder. In the router module of angularjs, you can use this function by defining resolve.
angular-ui-router
Use the same principle.Option 2
Don’t use {{ }} placeholders, use the
ng-bind
directive. But this solution is not flexible.For example, using {{ }}, you can write it like this
But that’s all you can do after using the
ng-bind
command.A lot of useless empty tags will appear. Not conducive to maintenance. And the page will appear blank.
It is recommended to use the first option. But the first one also has a shortcoming, that is, when the data is returned slowly, the view returns to the whiteboard, but it is still sent. You can use ng-animate and add loading animation when switching pages.
router.js
router.js
angular-ui-router
The module sample code is as follows// Try the code
一定要注意,视图里面不能再重复指定控制器名称。否则会报错
, it should be that the controller name has been specified in the route.