jjzjj

angular-promise

全部标签

javascript - 使用清晰设计系统构建 Angular 2 应用程序

从他们的官方tutorial添加ClarityDesignSystem后,我收到此错误到Angular25minquickstart.浏览器控制台中的错误并没有多大帮助,有什么建议吗?zone.js:1382GEThttp://localhost:3000/clarity-angular404(NotFound)Error:(SystemJS)XHRerror(404NotFound)loadinghttp://localhost:3000/clarity-angular(…)应用程序模块.tsimport{NgModule}from'@angular/core';import{Bro

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 - 使用 'Promise' 与不使用 'Promise' : in which cases?

我不知道SO是否适合提出这样的问题。我知道一点Promises,我在Node/Express环境中使用它们来“修复”Node的异步行为查询数据库(=等待数据库回答,然后做一些事情)。然而,我使用它们的次数越多,我就越不知道何时不用它们。例如,我写了一段这样的代码(用于查询GoogleMatrixAPI的本地脚本).......for(vari=0;i{}...我不知道在这里使用Promise.all是否有意义...有规律可知吗?我没有得到的行为?换句话说,我什么时候知道我的脚本运行没有正确参数的函数存在“风险”(argument从另一个函数返回这不是“结束”)...?谢谢。

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 - Promise.then 不执行

在下面的代码块中,只有“firstpromise”被记录到控制台。这是为什么?我试图编写一个测试来弄清楚.then()在.catch()之后是如何执行的,但当除了第一个promise之外什么都没有运行时,我感到很惊讶。这是怎么回事?functionfoo(){returnnewPromise((resolve,reject)=>{returnconsole.log('firstpromise')}).then(()=>console.log('firstthen')).catch(()=>console.log('catchblock')).then(()=>console.log('

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 - 如何避免在 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