对于Angular2,为什么具有相同组件的两个页面(两个选项卡)会相互影响? [英] For Angular2, why do two pages (two tabs) having the same component affect each other?

查看:254
本文介绍了对于Angular2,为什么具有相同组件的两个页面(两个选项卡)会相互影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是Angular2应用,该组件在这里简化为:

This is an Angular2 app, and the component is simplified here as:

@Component({
    selector: 'courses',
    template: `
        <input [(ngModel)]="wahla">
        <input [(ngModel)]="wahla">
        {{ wahla }}
        `
})
export class CoursesComponent {
    wahla = "hmm hmm ha ha";
}

我认为该应用程序在双向绑定的页面上运行良好,但是如果我使用 http://localhost:3000/打开另一个标签, ,然后在第一页的第一个输入框中粘贴或键入一些内容,然后第二个选项卡实际上对其第一个输入框进行更新,而第二个输入框和静态文本不更新.

I think the app works fine in one page with the two-way binding, but if I open up another tab with http://localhost:3000/ and then paste something or type something in the first page's first input box, then the second tab actually gets updated for its first input box, while the 2nd input box and the static text do not update.

对于第一个标签,一切都会按预期进行更新.

For the first tab, everything is updated as expected.

这是应该发生的还是可能出什么问题?这是使用npm start运行的,该npm start运行带有BrowserSync的精简服务器.

Is this supposed to happen or what might be wrong? This is running using npm start which is running a lite-server with BrowserSync.

推荐答案

这是lite-server的功能,而不是bug或看起来像是一个的东西.

That is a functionality of lite-server and not a bug or something as it might appear to be one.

要实现此目标,请lite-server 使用 JavaScript扩展

To make this happen lite-server uses a javascript extention Browsersync.

lite-server的npm页面上,这样提及

On lite-server's npm page it is mentioned like this

lite-server是一个围绕BrowserSync的简单自定义包装, SPA服务很容易.

lite-server is a simple customized wrapper around BrowserSync to make it easy to serve SPAs.

BrowserSync这样将其放在其网站

节省时间的同步浏览器测试

Time-saving synchronised browser testing

这清除了所有疑云

每个网页,设备和浏览器的测试时间都在增加 呈指数增长.从实时重新加载到URL推送, form replication 单击镜像,Browsersync便省去了重复的手动任务.

With each web page, device and browser, testing time grows exponentially. From live reloads to URL pushing, form replication to click mirroring, Browsersync cuts out repetitive manual tasks.

这篇关于对于Angular2,为什么具有相同组件的两个页面(两个选项卡)会相互影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆