草庐IT

羊了个羊源码H5,TypeScript,LAYA引擎

全部标签

javascript - 类型 'number' 不可分配给类型 'Date' - Typescript 未编译

我有以下用于jquery计时器插件的代码。编译器给我错误:“类型‘数字’不可分配给类型‘日期’”$(function(){varnote=$('#note'),ts=newDate(2012,0,1),newYear=false;if((newDate())>ts){ts=(newDate()).getTime()+24*60*60*1000;//counting24hoursnewYear=false;}});});}; 最佳答案 您需要创建一个新的Date实例:if((newDate())>ts){ts=newDate((new

javascript - 输入和输出,如何使用它们来遵循 Angular 2 风格指南的命名约定?

在我了解之前,我曾经像这样定义我的指令:...inputs:['onOutside']...exportclassClickOutsideDirective{@Output()onOutside:EventEmitter=newEventEmitter();}但后来我阅读了风格指南,它说你不应该在输出前加上on前缀因为Angular2支持on-模板中的语法。所以我想把它改成这样:@Input()outsideClick:any;@Output()outsideClick:EventEmitter=newEventEmitter();但是,我发现很难将@Input分开名称来自Output

javascript - 找不到 Angular2.0.0 管道 ''

错误:Error:Templateparseerrors:Thepipe'datefromiso'couldnotbefound管道:import{Pipe,PipeTransform}from"@angular/core";@Pipe({name:'datefromiso'})exportclassDateFromISOimplementsPipeTransform{transform(value:any,args:string[]):string{if(value){vardate=valueinstanceofDate?value:newDate(value);returndat

javascript - Angular 2 - 点击事件下载文件

我无法在任何地方找到答案,希望有人能提供帮助。我在表格单元格内的模板中定义了一个Angular2click事件:fileName.txt在typescript组件中,我需要帮助来定义一个方法click2Download(),它会自动开始将fileName.txt下载到客户端的浏览器。注意:文件在同一域中,例如:http://example.com/fileName.txt有什么方法可以用Angular2做到这一点吗? 最佳答案 你试过了吗:window.location.href='...';?要强制下载文件,您应该使用html属性

javascript - 使用异步/等待时在 Express 中捕获未处理的异常

看下面的TypeScript代码:app.get('/test_feature',function(req:Request,res:Response){thrownewError("Thisisthebug");});app.use(logErrors);functionlogErrors(err:Error,req:Request,res:Response,next:NextFunction){console.log(err);mongoDal.log(err.message,err);next(err);}在这里,我在请求处理程序中抛出一个错误,它会按预期触发logErrors函数

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 - 第二个 .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 - TS1148 ~ 如何使用 --module : "import" and typescript 2. x "none"

我目前正在使用一些旧版JavaScript开发一个项目。该应用程序不包含模块加载器,它只是将所有内容作为全局变量放入window对象中。遗憾的是,接触遗留代码并包含模块加载器对我来说不是一个可行的选择。我想在我自己的代码中使用typescript。我设置了typescript编译器选项module:"none"在我的tsconfig.json中,我只使用命名空间来组织我自己的代码。到目前为止效果很好。..到现在为止:import*asRxfrom'rxjs';..Rx.Observable.from(['foo',bar']);...//ResultsinTypeScript-Erro