我有一个订阅调用,只需要一次接收数据.它开启的Angular 2页面长期运行.
我想确保订阅第一次收到数据后不会导致内存泄漏和取消订阅的任何问题.
这是我的服务,它提出了一个api查询.它使用.first,因此一旦收到数据就应该清理它.
getData(): Observable<string> {
let _url = SOME_API_URL;
return this._http.get(_url).first().map((response: Response) => { return response.json(); });
}
Run Code Online (Sandbox Code Playgroud)
这是我的Ng2订阅.我是否需要做任何事情确保在收到第一()数据后清理所有内容?
this._service.getData().subscribe((data: any) => {
// Do something once.
// DO I HAVE TO UNSUBSCRIBE OR WILL THE CLEANUP HAPPEN DUE TO THE ABOVE FIRST() CALL?
});
Run Code Online (Sandbox Code Playgroud)
我可以使用ngDestory,但由于页面长时间运行而且不经常刷新,因此不会被调用.
我有一个MVC应用程序,有许多表单.提交表单时,它将用户gps坐标传递给服务器.我还想传递客户当前的日期时间.
有没有人对最佳方法有任何想法?
表单是标准的html表单并使用基本提交.
我的表格看起来像下面那个.那么我如何才能最好地将javascript datetime值附加到提交调用?
@using (Ajax.BeginForm("CheckIn", "Home", "Nothing", new AjaxOptions { }))
{
<fieldset>
<p>Move your Tile here to let those around you see it...</p>
<input type="hidden" name="lat" id="hckLat" value="" />
<input type="hidden" name="lon" id="hckLon" value="" />
<input type="hidden" name="date" id="hckDate" value="" />
<input type="submit" value="Check In!" />
</fieldset>
}
Run Code Online (Sandbox Code Playgroud) 我正在构建我的第一个Angular 2应用程序,并且在链接可观察订阅时遇到问题.
以下代码适用于Chrome,但不适用于Firefox和IE.
下面这样做的正确方法是什么?我需要获取用户的当前位置,然后将其传递给第二个调用(getTiles).
我没有在Web开发浏览器工具中看到任何错误.这也是我在localhost上运行的时候.该网站尚未部署.我不确定这是否相关.
我正在使用Angular 2.0.0-rc.2.
ngOnInit(): void {
this._LocationService.getLocation().subscribe(
location => {this.location = location;
// make the next call using the result of the first observable
this._TilesService.getTiles(0, location).subscribe(
tiles => {this.tiles = tiles; this.index = 1;},
error => this.errorMessage = <any>error);
});
}
Run Code Online (Sandbox Code Playgroud)
这是位置服务......
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Observer } from 'rxjs/Observer';
import { ILocation } …Run Code Online (Sandbox Code Playgroud) 我有一个 Angular 2 应用程序,我只想在 https 上运行。将使用 http 的地址重定向到使用 https 的最佳方法是什么?
我正在尝试使用.net将字符串解析为XElement.我每次都收到此错误,无法解决原因...
"根级别的数据无效.第1行,第1位."
我试过HTMLEncode但它没有帮助.我也在LinqPad玩过它.
我试图像这样解析字符串(数据是一个字符串)...
XElement d = XElement.Parse(data);
Run Code Online (Sandbox Code Playgroud)
我想解析的字符串如下所示.有人可以告诉我为什么这不会解析?谢谢.
"<?xml version=\"1.0\" encoding=\"utf-8\"?><rss version=\"2.0\" xmlns:media=\"http://search.yahoo.com/mrss/\"><channel><item><title><![CDATA[Download the Bath SU app]]></title><link><![CDATA[http://www.bathstudent.com/news/article/6003/3515/]]></link><pubDate>Thu, 29 Sep 2011 11:59:00 GMT</pubDate><description><![CDATA[Discovering the latest news and events, enjoying exclusive offers, finding your way around campus, checking lecture times... there's an app for that!\r\n\r\nYes, the official University of Bath Students' Union iPhone and Android app is now available free on the Apple App Store. Just search for University of Bath Student Union on the App Store or Android Market and …Run Code Online (Sandbox Code Playgroud) 我在SQL Server中有一个表,其中包含geography datatype列.我想查询此表以查找落在另一个给定地理点附近(在一个范围内)的行.有没有人对最佳方法有任何想法?我有2个选项可以在哪里进行此类查询.我可以将它作为存储过程在sql server上编写,或者我可以在c#代码中编写它,因为我正在使用Entity Framework进行数据访问.
我会有一个范围(例如100米)和传递给它的地理点的查询.伪代码就是这样的......
选择rows.geo在给定地理点范围内的行
我在网上找到SQL Server中的地理查询示例时遇到了一些麻烦.
任何帮助,将不胜感激.
我试图从Angular 2调用一个Web Api端点.在IE和Chrome中它一切正常但在Firefox中我得到一个json解析错误.我认为它返回XML而不是Json.我认为设置内容类型会解决这个问题.我的代码看起来是否正确?有任何想法吗?
let _tileUrl = XXX;
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this._http.get(_tileUrl, options)
.map((response: Response) => <ITile[]>response.json())
.catch(this.handleError);
Run Code Online (Sandbox Code Playgroud) 我在javascript文件中遇到了一个对象预期错误.在这种情况下是否意味着jQuery文件没有正确包含?
导致错误的行是......
$(function () {
Run Code Online (Sandbox Code Playgroud)
浏览器中的错误是......
Message: Object expected
Line: 6
Char: 1
Code: 0
Run Code Online (Sandbox Code Playgroud) 因此,根据我的内容,实体框架中尚不支持Geography SQL类型.
我想知道是否有人能解决我遇到的问题.我有一个ac#类,它有一些使用实体框架和LINQ的数据访问方法.这些方法正在将GPS坐标传递给它们.数据库(和实体框架类型)上有经度和纬度字段,这些字段在创建行时填充.一切正常.
我想要做的是让我的LINQ查询拉回给定GPS坐标附近(半径范围内)的行.我不想开始使用存储过程,因为这将是架构更改.
有没有人对此有任何想法?我正在努力争取创意.
在调用string.format时使用的格式字符串是否有一种方法可以包含{不用于子字符串插入的字符?
比如我怎么能这样做......
string.format("my format has this { in it {0}", abc);
Run Code Online (Sandbox Code Playgroud)
返回...
"my format has this { in it abc"
Run Code Online (Sandbox Code Playgroud)
我需要将此作为我在HTML中创建的字符串,并将构建一个javascript脚本块.
谢谢
.net ×4
angular ×4
c# ×3
javascript ×2
asp.net-mvc ×1
exception ×1
geography ×1
gps ×1
jquery ×1
linq ×1
razor ×1
rxjs ×1
sql ×1
sql-server ×1
xml ×1