草庐IT

javascript - 模块化 Angular

我正在开始一个新的Angular项目并尝试模块化我的所有代码——我厌倦了拥有大量的app.js文件,而且因为我正在为一家公司开发一个平台,所以我的代码整洁且模块化以便于测试、清洁和易于过渡到Angular2。目前,我有三个Angular文件来设置所有内容:Angular.module.jsangular.module('app',[/*SharedModules*/'app.config','app.states'/*FeatureAreas*/])Angular.config.jsangular.module('app',[/*AngularModules*/'ngResource'

javascript - Angular Karma console.log 不起作用

我在我的项目中使用KarmaAngularMochaChai。我正在做TDD并想测试我的更改。我在我的test.js文件中做了一个console.log但karmaconsole没有显示。我什至不确定如何启用它?这是我的karma.config.js:module.exports=function(config){config.set({//basepaththatwillbeusedtoresolveallpatterns(eg.files,exclude)basePath:'',//frameworkstouse//availableframeworks:https://npmjs

javascript - 在javascript中实现类似angular ng-repeat的功能

我目前正在编写代码以实现类似ng-repeat的Angular。基本上是html中的for循环。该代码采用类为“循环”的每个元素,并使用通过“信息”属性提供的信息对其进行处理。这是代码:HTML-i-Javascript$(".loop").each(function(i){varloop_info=$(this).attr("data-info");varfin=loop_info.match(/(.*)in(\d+)to(\d+)/);varvariable=fin[1],initial=fin[2],final=fin[3];varhtm=$(this).html(),print

javascript - Typescript 接口(interface)中的日期在检查时实际上是字符串

不幸的是,重现此代码的总代码会很长,所以我希望我的问题很明显,我可以轻松提供。如果需要,我会发布更完整的解决方案。首先,我定义了一个接口(interface):exportinterfaceITest{myDate:Date;}然后我创建了一个数组用于测试:exportconstTEST:ITest[]=[{myDate:newDate(1995,8,1)}]我使用Angular2中的一项服务公开这些内容,该服务从angular2-in-memory-web-api访问InMemoryDbService。我调用它并获取数组的代码如下:get():Promise{returnthis.h

javascript - 重试后如何获取catchWhen?

我想重试几次get请求,并在出现错误时延迟一秒,但如果所有尝试都失败,则执行错误处理程序。以下代码重试请求,但从未执行catch。我该如何解决?import{Response,Http}from'@angular/http';import{Observable}from'rxjs/Rx';import'rxjs/add/operator/catch';import'rxjs/add/operator/map';this.http.get("/api/getData").map(data=>{console.log('get')returndata.json()}).retryWhen(

javascript - Angular 2获取上一页网址

我有两个组件。客户和装运组件。当用户从Shipment组件转到Customer组件时。我想将Customer组件直接连接到Shipment组件。我用的就是这个方法。this._location.back();来自Locationangular/common。这个方法总是指向后台页面。但是我想直接到我来自装运组件的时候。 最佳答案 Angular6更新将下面的代码插入到包含您的2个组件的父组件中:-import{Router,RoutesRecognized}from"@angular/router";import{filter,pa

javascript - Angular 2 - Firebase 在页面刷新时保持登录状态

所以我真的很接近解决这个问题了。基本上,我有登录工作,我有代码设置来监视onAuthStateChanged,但问题是当我刷新页面时,即使用户当前已登录,它仍然重定向到/login页面因为我已经设置了authguard,检查用户是否登录。我有一个身份验证服务设置,可以执行所有身份验证检查。在我的auth服务构造函数中,这是我设置onAuthStateChanged代码的地方:constructor(privateauth:AngularFireAuth,privaterouter:Router,privatedb:AngularFireDatabase,){firebase.auth(

javascript - Angular2/Typescript/ngRx - 类型错误 : Cannot assign to read only property of object

在构造函数中我做了这样的事情selectedDate:Object;//construtorthis.selectedDate={};this.selectedDate['date']=newDate();this.selectedDate['pristine']=newDate();在另一个通过单击按钮调用的函数中,我执行以下操作:this.selectedDate['date']=newDate(this.selectedDate['pristine']);我收到以下错误:TypeError:Cannotassigntoreadonlyproperty'date'ofobject'

javascript - 如何手动触发点击事件?

我正在尝试以编程方式触发文档点击。我的测试组件显示在页面的多个位置,我想在单击测试组件或触发文档点击时将它们全部隐藏。@Component({selector:'test-comp',template:`stuffandmore…`})exportclassTestComponent{showMenu:boolean;constructor(publicelementRef:ElementRef){}@HostListener('document:click',['$event'])documentClick(event:MouseEvent){//hidemycomponentwhe

javascript - 递归调用异步 API 调用

我正在尝试从每次调用仅返回1000项的API中获取数据,并且我想递归执行此操作,直到获得所有数据。我事先不知道总共有多少元素,所以每次打电话后我都要检查如果调用是同步的,我会使用这样的东西:functionfetch(all,start){constnewData=getData(start,1000);all=all.concat(newData);return(newData.length===1000)?fetch(all,all.length):all;}但是,此处的getData()调用是异步的。使用Promise.all()不起作用,因为我事先不知道我需要多少调用,所以我无