Angular 6 http请求处理(Angular 6 http request handling)
我正在使用Angular 6构建一个Web应用程序。我有一个服务,它有一个方法,当它被调用并给出正确的参数时,向服务器发送POST请求并返回数据。 这是方法:
public getDataFromServer(request, url): any { return this.httpClient.post(url, request, {headers: new HttpHeaders().set(this.headername, this.header ) }); }
现在我有多个使用此方法的组件。 菜单中的每个页面( 家庭,关于,新闻等)都使用这个。 我想创建一个请求处理程序,它将发送第一个请求(假设我登录),然后等待,直到我收到响应,然后再发送另一个请求。 如果我点击页面新闻 ,然后在页面上点击,我会得到回复,我已经在网页上,并在我得到回应后,下一个请求将成为页面新闻上的一个,但我已经在网页上。 如果我在网页上,我不希望要求新闻被执行。
我看到一些使用http拦截器的帖子,但我不希望请求甚至会被发送到http。 请求不得发送。 提前谢谢你的帮助。
I'm building a web app using Angular 6. I have a service that has a method which when called and given right parameters, sends a POST request to the server and returns the data. This is the method:
public getDataFromServer(request, url): any { return this.httpClient.post(url, request, {headers: new HttpHeaders().set(this.headername, this.header ) }); }
Now I have multiple components which uses this method. Every page in the menu (home, about, news, etc..) uses this. I want to make a request handler that would send the first request (let's say I login) and then wait until I get a response before sending another request. If I were to click on page news and then on page about before I would get response, I would already be on page about and after I get response the next request will be the one on page news, but I'm already on page about. I don't want request on news to be executed if I'm on page about.
I saw some posts with http interceptor, but I don't want the request to even be made to http. Request must not be sent. Thank you for your help in advance.
原文:https://stackoverflow.com/questions/50945066
最满意答案
看看我提出的关于将ListView绑定连接起来并适用于所有CRUD操作的演示。
http://www.flaskofespresso.com/2012/01/windows-8-metro-app-listview-binding-and-editing/
Check out this demo that I put up regarding getting ListView binding hooked up and working for all CRUD operations.
http://www.flaskofespresso.com/2012/01/windows-8-metro-app-listview-binding-and-editing/
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
不要在您的视图中创建CollectionViewSource 。 相反,在视图模型中创建一个ICollectionView属性并将ListView.ItemsSource绑定到它。 完成此操作后,可以将逻辑放入FilterText属性的setter中,以便在用户更改ICollectionView时调用Refresh() 。 您会发现这也简化了排序问题:您可以将排序逻辑构建到视图模型中,然后公开视图可以使用的命令。 编辑 以下是使用MVVM动态排序和过滤集合视图的一个非常简单的演示。 这个演示没有实现Filt ...
-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
在CollectionViewSource View属性上调用Refresh()以刷新它。 如果您想在按钮单击时执行此操作,则需要先从窗口资源访问CollectionViewSource,然后在其View上调用刷新。 ((CollectionViewSource)this.Resources["cvsCustomers"]).View.Refresh(); Call Refresh() on View property of CollectionViewSource to get it refreshed ...
-
我按你想要的输出去了。 请检查并告知这是否是您想要的。 public partial class WinExpander : Window { public WinExpander() { InitializeComponent(); this.DataContext = new ViewModel(); } } public class ViewModel { public List
Countries ... -
看看我提出的关于将ListView绑定连接起来并适用于所有CRUD操作的演示。 http://www.flaskofespresso.com/2012/01/windows-8-metro-app-listview-binding-and-editing/ Check out this demo that I put up regarding getting ListView binding hooked up and working for all CRUD operations. http://www. ...
-
使用d:DesignInstance和CollectionViewSource(Using d:DesignInstance with CollectionViewSource)[2023-08-18]
首先尝试定义一个群体应该如何看待我的意思是群体的标题等等 public class Group: ObservableCollection , INotifyPropertyChanged { public Group(string name,IEnumerable items):base(items) { Name=name; } //more ... } 这个类不仅仅是静态数据,它处理不断变化的数据。 现在,如果你使用MVVM模型在你的viewmodel(hom ... -
你可以试试这个 var order = yourCollection.OrderByDescending(y => y.ItemA.IndexOf("LOVEU")); 这将基于属性Name进行排序这里是它的Name ,默认情况下它将按升序排序 编辑:请在这里查看dotnetfiddle的完整代码 You could try this var order = yourCollection.OrderByDescending(y => y.ItemA.IndexOf("LOVEU")); This w ...
-
为了在对集合进行更改后进行UI更新,您需要实现INotifyCollectionChanged 。 这会在更改发生时通知用户界面,并通过在更改之上重新绑定用户界面来响应。 但是实现这个接口是相当重要的。 相反,你应该使用ObservableCollection
来代替List ,并且场景应该可以正常工作 private ObservableCollection _expenses = new ObservableCollection (); public Obse ... -
检查这个 1) CollectionView过滤 过滤需要基于过滤器将发生的委托(谓词)。 Predicate根据它返回的值true或false接受项目an,它选择或取消选择一个元素。 this.Source.Filter = item => { ViewItem vitem = item as ViewItem; return vItem != null && vitem.Name.Contains("A"); }; 2) 动态地处理数据 Al last I have found a s ...