Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.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
如何根据c#代码中的更改刷新角度视图_C#_Angular - Fatal编程技术网

如何根据c#代码中的更改刷新角度视图

如何根据c#代码中的更改刷新角度视图,c#,angular,C#,Angular,我开发了一个使用ASP.NET WebApi的Angular应用程序。 我使用SQLServerServiceBroker来通知数据库中的更改,这些更改是由外部应用程序进行的 using (var otherNotifier = new EntityChangeNotifier<Product, StoreDbContext>(x => x.Name == "Desk")) { otherNotifier.Changed += (sender, e) =>

我开发了一个使用ASP.NET WebApi的Angular应用程序。 我使用SQLServerServiceBroker来通知数据库中的更改,这些更改是由外部应用程序进行的

using (var otherNotifier = new EntityChangeNotifier<Product, StoreDbContext>(x => x.Name == "Desk"))
{
    otherNotifier.Changed += (sender, e) =>
    {
        Console.WriteLine(e.Results.Count());
    };

    Console.WriteLine("Press any key to stop listening for changes...");
    Console.ReadKey(true);
}
使用(var otherNotifier=newEntityChangeNotifier(x=>x.Name==“桌面”))
{
otherNotifier.Changed+=(发件人,e)=>
{
Console.WriteLine(e.Results.Count());
};
Console.WriteLine(“按任意键停止侦听更改…”);
Console.ReadKey(true);
}
外部API更改了数据库中的记录,我得到了正确的通知。
我想知道,当我检测到更改时,是否可以以某种方式刷新角度视图。

对于您的场景,通过信号器推送通知是最好的方式。你的问题有几种解决办法。 我已经给了你。 SSE和WebSockets这两种技术之间的差异并不大,都是不错的选择。到目前为止,这两种技术之间最大的区别在于WebSocket是全双工的,客户端和服务器之间的双向通信,而SSE是单向的


您可以阅读全文

您可以通过推送通知实现这一点。对于.NET应用程序,SignalR是最好的框架,但你也可以在web API中实现只要看看这个或看看我对尽可能最简单的方法感兴趣。对于最简单的方法,你需要在API上创建get请求,并定期从angular应用程序调用它以检查更新你需要一个例子吗?我需要最简单但反复调用的API将产生大量不需要的网络流量。其他选项中哪一个是最简单的?推送通知是否足够?