我通过服务公开HTTP GET请求,并且有几个组件正在使用此数据(用户的配置文件详细信息).我希望第一个组件请求实际执行到服务器的HTTP GET请求并缓存结果,以便后续请求将使用缓存数据,而不是再次调用服务器.
这是服务的一个示例,您如何推荐使用Angular2和typescript实现此缓存层.
import {Inject, Injectable} from 'angular2/core';
import {Http, Headers} from "angular2/http";
import {JsonHeaders} from "./BaseHeaders";
import {ProfileDetails} from "../models/profileDetails";
@Injectable()
export class ProfileService{
myProfileDetails: ProfileDetails = null;
constructor(private http:Http) {
}
getUserProfile(userId:number) {
return this.http.get('/users/' + userId + '/profile/', {
headers: headers
})
.map(response => {
if(response.status==400) {
return "FAILURE";
} else if(response.status == 200) {
this.myProfileDetails = new ProfileDetails(response.json());
return this.myProfileDetails;
}
});
}
}
Run Code Online (Sandbox Code Playgroud) 我在angular2组件中定义templateUrl时尝试使用相对路径,如下所述:http://schwarty.com/2015/12/22/angular2-relative-paths-for-templateurl-and-styleurls/
@Component({
selector: 'login-app',
moduleId: module.id,
templateUrl: './app.html'
})
Run Code Online (Sandbox Code Playgroud)
虽然我一直在:
错误:未定义模块
我在ts编译设置上使用-m commonjs.
如何使它工作?
我想在angular2组件中为*ng-for DIV实现无限滚动.为此,我需要以某种方式通过角度方法挂钩窗口onScroll事件.然后在角度我将能够在用户滚动通过页面的某个点时将更多项目加载到数据项数组中.
任何人都有想法如何从angular(在ng2组件内)挂钩window.scroll事件?
我正在尝试在*ngClass中添加多个值,以前用于以前的alpha版本,现在似乎不适用于angular2 beta:
<i *ngClass="['fa','fa-star']"></i>
Run Code Online (Sandbox Code Playgroud)
它会产生错误:
EXCEPTION:TypeError:在PostView @ 30:27中的[['fa','fa-star']中无法读取未定义的属性'add'
我在这里错过了什么?
自从我将最新版本的log4net(1.2.11.0)放在我的解决方案项目上之后,我收到了附加的错误.这在部署后立即在服务器上发生,当我再次刷新时,它会消失,直到下一次部署.请注意我已经尝试了以下版本的重定向代码,但它没有帮助:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
<bindingRedirect oldVersion="1.2.10.0" newVersion="1.2.11.0" />
</dependentAssembly>
</assemblyBinding>
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
'/'应用程序中的服务器错误.
无法加载文件或程序集'log4net,Version = 1.2.10.0,Culture = neutral,PublicKeyToken = 1b44e1d426115821'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040)
异常详细信息:System.IO.FileLoadException:无法加载文件或程序集'log4net,Version = 1.2.10.0,Culture = neutral,PublicKeyToken = 1b44e1d426115821'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040)
来源错误:
Line 76: </script>
Line 77: <form id="form1" runat="server">
Line 78: <asp:ScriptManager ID="radscriptmanager" runat="server">
Line 79: </asp:ScriptManager>
Line 80: <asp:ContentPlaceHolder ID="cphAfterScriptManager" runat="server">
Run Code Online (Sandbox Code Playgroud)
源文件:MainFront.Master Line:78
程序集加载跟踪:以下信息有助于确定无法加载程序集"log4net,Version = 1.2.10.0,Culture = neutral,PublicKeyToken = 1b44e1d426115821"的原因.
我遇到了EF4对象上下文的问题,我将其存储在HttpContext.Current.Items中,然后在完全处理请求后立即处理.
在Aplication_EndRequest事件中,我调用RepositoryContext的Terminate()方法,该方法将从HttpContext.Current.Items集合中找到活动的ObjectContext,并在其连接上调用Close()并在其上调用Dispose().
问题是,有时候我的某个页面会出现奇怪的行为.在某些情况下,我得到一个错误说:
ObjectContext实例已被释放,不能再用于需要连接的操作
我想也许这可能发生,因为不仅页面请求一旦完成就会调用Application_EndRequest事件,而且还会调用图像请求等等,因此有时其他请求可能会在完成其工作之前处理主页面请求ObjectContext,但这应该是因为一切都是在集合HttpContext.Current.Items上进行的,所以当然不能在HTTP请求之间共享.
此外,从研究可能是由于一些数据库请求的延迟加载引起的,但这不应该是这里的情况,因为我没有在代码上的其他任何地方调用Dispose(我已经检查过),因此EndRequest上的Dispose()应该只有在一切都结束时才会被召唤,不应该吗?
关于可能导致这种情况的任何想法?我该怎么测试呢?你会建议什么?
谢谢!
我有一个父组件和一个子组件.我希望能够从父组件上的某个方法调用子组件上的一些子方法.有没有办法获得父类的子组件实例的引用并调用子的公共方法?
@Component({
selector: 'child-component'
})
@View({
template: `<div>child</div>`
})
class ChildComponent{
constructor () {
}
doChildEvent () {
// some child event
}
}
@Component({
selector: 'parent-component'
})
@View({
template: `
<child-component #child></child-component>
`,
directives: [
ChildComponent
]
})
class ParentComponent {
private child:ChildComponent;
constructor () {
}
onSomeParentEvent() {
this.child.doChildEvent();
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试在模板中对子进行哈希并在类中引用它但没有成功.