草庐IT

javascript - 如何在 Angular 2 中为脚本和样式指定基本 href?

我目前正在研究Angular2,我对如何将样式和脚本注入(inject)index.html有疑问通过AngularCLIbuild命令(我指的是在angular-cli.json中定义的脚本和样式)。问题是我在嵌套位置运行应用程序,例如:http://domain.com/my_app同时可以设置,注入(inject)的脚本和样式总是指向src到根域。即/而不是/my_app.当然,这会在尝试查看页面时导致404。我正在服务/dist直接。Nginx配置:server{server_namedomain.com;listen80;location/my_app{alias/srv/w

javascript - 添加提供程序@NgModule 时出现 Angular2 "No provider for Service!"错误

我有一个应用程序模块和单组件应用程序(用于演示我的问题),并出现以下错误:Errorin./AppComponentclassAppComponent_Host-inlinetemplate:0:0causedby:NoproviderforUserService!;Zone:;Task:Promise.then;Value:AppModule代码:import{NgModule}from'@angular/core';import{BrowserModule}from'@angular/platform-browser';import{UserService}from'./compo

javascript - 使用指令将组件动态添加到子元素

尝试使用指令将组件动态放置到子元素。组件(作为模板):@Component({selector:'ps-tooltip',template:`{{content}}`})exportclassTooltipComponent{@Input()content:string;}指令:import{TooltipComponent}from'./tooltip.component';@Directive({selector:'[ps-tooltip]',})exportclassTooltipDirectiveimplementsAfterViewInit{@Input('ps-toolti

javascript - Angular 2 - 在 iframe 上注入(inject)自定义 header

我疯狂地尝试将请求自定义header(类似于'AUTH-TOKEN':'SomeToken123')注入(inject)到Angular4上。我需要向iframe页面传递一些必需的自定义header参数。谁能帮帮我?foo.component.html组件.ts@Component({selector:'app-foo',templateUrl:'./foo.component.html'})exportclassFooComponentimplementsOnInit{@ViewChild('iframe')iframe:ElementRef;publicisLoading:Bool

javascript - Angular 拦截器和 CORS

我正在尝试编写一个拦截器以使用Angular向所有HTTP请求添加一个token。我大致使用这里给出的食谱-https://thinkster.io/interceptors因此代码使用了http模块工厂和一个tokenInterceptor()函数。我可以成功地将token作为header添加到请求中-但现在当它通过拦截器时,它会被某种CORS阻塞机制阻塞。我在Chrome控制台中收到此错误-XMLHttpRequestcannotloadhttp://127.0.0.1:/.Responsetopreflightrequestdoesn'tpassaccesscontrolchec

javascript - 第二个 .then() on promise 被调用时数据未定义

我在名为accountManager的服务中有一个函数返回如下所示的promise:这个promise上的.then()会触发并打印出预期的响应。signIn(email:String,password:String):Promise{returnthis.http.post('http://localhost:3000/api/signin',JSON.stringify({"email":email,"password":password}),{headers:this.headers}).toPromise().then(res=>{//**Thisisdefined**cons

javascript - RxJS:只有在不同的情况下才去抖流

我想去抖一个流-但前提是源值与以前相同。我如何使用RxJS5做到这一点?如果值相同并且我之前在指定的时间窗口内发出过,我不想发出值。我应该能够使用流中的值-或者比较类似于distinctUntilChanged的​​函数。 最佳答案 这取决于您要做什么;当我尝试做类似的事情时,我遇到了这个问题,基本上是去抖动,但对对象的不同值使用不同的去抖动。在尝试了jayphelps的解决方案后,我无法让它按照我想要的方式运行。经过多次来回,结果发现有一种内置的简单方法可以做到这一点:groupby。constpriceUpdates=[{bid

javascript - 无法绑定(bind)到 'disabled',因为它不是 '<button>' 的已知属性

我刚开始学习Angular,但遇到以下错误:无法绑定(bind)到“已禁用”,因为它不是的已知属性.在互联网上搜索我只是发现了类似的错误,但它们与未导入FormsModule这一事实有关,这似乎不是我的情况。app.components.tsimport{Component}from'@angular/core';@Component({selector:'app-root',templateUrl:'./app.component.html',styleUrls:['./app.component.css']})exportclassAppComponent{title='app';

javascript - 如何避免在 Angular 2 中多次执行不纯管道?

您好,我正在使用Angular2管道返回对象的键,它是一个不纯的管道,它被多次执行,这会阻塞其他一些脚本,我如何避免多次执行不纯的管道?我的代码如下:import{Pipe,PipeTransform}from'@angular/core';@Pipe({name:'NgforObjPipe',pure:true})exportclassNgforObjPipeimplementsPipeTransform{transform(value,args:string[]):any{letkeys=[];for(letkeyinvalue){keys.push({key:key,value:

javascript - 按类不返回元素的 Angular Fixture DebugElement 查询

正如Angular.io框架测试文档所建议的,我一直在尝试使用AngularTestbed+Karma测试运行器来使用DebugElement查询。我创建了一个jqwidgetsTree组件,它生成类'.jqx-tree-item-li'的li元素。以下在DOM测试中直接使用javascript的测试通过了GREEN:it('Elementsofclassjqx-tree-item-lifoundusinggetElementsByClassName',(done)=>{this.fixture.whenStable().then(()=>{varelementArray=docume