Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Events Angular2:如何知道浏览器是否重新加载?_Events_Angular - Fatal编程技术网

Events Angular2:如何知道浏览器是否重新加载?

Events Angular2:如何知道浏览器是否重新加载?,events,angular,Events,Angular,这是ng-book2中的一段:默认情况下,Javascript会将单击事件传播到所有父组件。由于单击事件传播到父级,因此我们的浏览器尝试跟踪空链接。 要解决这个问题,我们需要使click事件处理程序返回false。这将确保浏览器不会尝试刷新页面 问题:如何知道浏览器是否重新加载?我用眼睛看不出来 以下是我的部分代码: import { Component } from "angular2/core"; @Component({ selector: 'reddit-article',

这是ng-book2中的一段:默认情况下,Javascript会将单击事件传播到所有父组件。由于单击事件传播到父级,因此我们的浏览器尝试跟踪空链接。 要解决这个问题,我们需要使click事件处理程序返回false。这将确保浏览器不会尝试刷新页面

问题:如何知道浏览器是否重新加载?我用眼睛看不出来

以下是我的部分代码:

import { Component } from "angular2/core";

@Component({
    selector: 'reddit-article',
    inputs: ['article'],
    templateUrl: 'app/redditArticle.html'
})

export class RedditArticleComponent {

    article: Article;

    constructor() {
       console.log('Just loaded!');
    }

    voteUp() {
        this.article.voteUp();
    }

    voteDown() {
        this.article.voteDown();
    }
}

export class Article {
    //title: string;
    //link: string;
    //votes: number;

    constructor(public title: string, public link: string, public votes: number) {
        //this.title = title;
        //this.link = link;
        //this.votes = votes;
    }
    voteUp(): boolean {
        this.votes++;
        return false;
    }

    voteDown(): boolean {
        this.votes--;
        return false;
    }

}

当您打开浏览器开发工具时,您知道在打印刚刚加载的附加
时发生了重新加载。确保在控制台(Chrome)中选中了
[x]preserve log

在书中,它表示没有“return false”;在voteUp()和voteDown()函数中,它将重新加载页面。当我尝试您的建议将信息打印到控制台时,发现“return false”和“return false”没有区别。你知道为什么吗?你能提供一个到该文件的链接吗?很抱歉回复太晚了。这是我的代码:在Angular 2中刷新页面之前,有没有办法触发事件?刷新是什么意思?什么活动?为了什么?
export class AppComponent {
  constructor() {
    console.log('just loaded');
  }
}