AngularJS advanced () solves the problem of abnormal display caused by refreshing AngualrJS pages

Source: Internet
Author: User

AngularJS advanced () solves the problem of abnormal display caused by refreshing AngualrJS pages
Solve the Problem of abnormal display caused by refreshing the AngualrJS page

As the saying goes, Details determine success or failure, as does programming. During the programming process, we may unconsciously ignore some details, but we do not know that these details are exactly the cause of the page display problems. I will give you an example here.

After the page is loaded normally, it is displayed as follows:

After you press F5 to refresh, the page is shown as follows:

Obviously, an exception is displayed on the page. Let's look at the Chrome error prompt,

The Code is as follows:

The above Code leads to errors.

Tracing

Let's review how errors occur. Normal page display is easy to understand when the page is loaded normally. The program follows the established data stream. However, after you press F5 to refresh it, $ stateParams. uid does not exist. If you call it again, the undefined error will occur, causing an exception in page loading.

How can this problem be solved?

First, you should add a variable judgment statement before the statement execution. If the variable exists and is not empty, you can continue to execute other processes. The Code is as follows: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + forward/K/b7d19zK/TwvcD4KPHA + forward/X3NKzyv08L3A + cjxwp1_vcd4kpha + forward = "" & $ stateParams. uid! = Null & typeof (instance. shopStatementDtl )! = "Undefined ")

{

.................

.................

}

Effect after execution:

Meiwenmeitu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.