如何在Angular中关闭ZoneAwareError?

时间:2019-07-29 09:01:06

标签: angular zone.js

我想在Angular中关闭ZoneAwareError来解决性能问题。

enter image description here enter image description here

我尝试在the Documents处找到解决方案,但找不到。

还有其他API可以解决此问题吗?

1 个答案:

答案 0 :(得分:0)

我通过重构捕获逻辑(如代码下)解决了它。

原样。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    [SerializeField] private float movementSpeed = 5.0f;
    [SerializeField] private bool isGrounded = false;

    private Rigidbody2D rb;

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    void Update()
    {
        move();
        jump();
    }

    private void move()
    {
        float move = Input.GetAxis("Horizontal");
        rb.velocity = new Vector2(movementSpeed * move * Time.deltaTime, rb.velocity.y);
    }

    private void jump()
    {
        if(Input.GetKeyDown(KeyCode.Space) && isGrounded == true)
        {
            Debug.Log("jump");
        }
    }

    void OnCollisionStay2D(Collision2D, col)
    {
        if(col.gameObject.tag == "Ground")
        {
            isGrounded = true;
        }
    }

    void OnCollisionExit2D(Collision2D, col)
    {
        if(col.gameObject.tag == "Ground")
        {
            isGrounded = false;
        }
    }
}

成为。

const promise = new Promise(() => {});
promise.catch(() => {});
promise.then(() => {});