草庐IT

angular-promise

全部标签

javascript - 如何找到由四个相同 Angular 组成的二维数组中最大的矩形?

考虑这个数组:[["B","C","C","C","C","B","B","C","A","A"],["B","A","C","B","B","A","B","B","A","A"],["B","C","B","C","A","A","A","B","C","B"],["B","B","B","A","C","B","A","C","B","A"],["A","A","A","C","A","C","C","B","A","C"],["A","B","B","A","A","C","B","C","C","C"],["C","B","A","A","C","B","B","C","A"

javascript - angular 5 - 仅当数组中存在元素时才添加类

在使用ng-for循环时,我想将类添加到项目,前提是项目的id存在于其他一些对象列表中。我试过这样的:item.Id==p.id)">或者这个:item.Id==p.id)?'Flag':''">但它没有编译。请注意,“favoriteList”可能会在“products”之后加载到页面。知道我该怎么做吗?谢谢! 最佳答案 问题出在你的some()方法上,举个例子component.html{{p.name}}component.css.Flag{background:red;}和component.tsproducts=[{"id

javascript - 在数组和对象之间使用逗号运算符的 Promise.all 如何工作?

我遇到过这段代码:constresults=awaitPromise.all([Model1.find({}),Model2.find({})],Model3.find({})),v1=results[0],v2=results[1],v3=results[2]用数组和单个对象调用all()—`Model*是Mongoose模型。这是一个很容易修复的错误,但我想了解它是如何给出结果值的,这些值是:v1持有Model1对应的所有文档v2持有Model2对应的所有文档v3未定义如thisansweronthecommaoperator中所述,我只希望Model3.find({})promi

javascript - 在 promise 中处理错误时返回成功

我有一个处理通过WebAPI执行的HTTP请求的promise:promise=promise.then(r=>{//...},error=>{if(error.status==404){//HereIcanfixanerrorandcontinueproperly}else{//Heretheerrorshouldbepropagatedfurtherinthepromise}}//laterinthecode:promise.catch(r=>{/*Moreerrorhandling*/});在代码的后面,这个promise链接到更多的错误检查。在出现404错误的情况下,我实际上可

javascript - 扩展 `Promise` 并更改 `then` 签名

我想延长Promise并更改then签名所以它的回调接收两个值。我尝试了不同的方法,其中两种已记录并经过测试here.遗憾的是,我遇到了各种错误,或者生成的类的行为不像Promise。方法一:WrappinganativePromiseexportclassMyWrappedPromise{constructor(data){this.data=data;this.promise=newPromise(evaluate.bind(data));}then(callback){this.promise.then(()=>callback(this.data,ADDITIONAL_DATA

javascript - 使用 Angular 加载部分页面并编译 Controller

在大型应用程序中,我们的Web应用程序可能会组织成单独的部分页面,以增加我们应用程序的模块化。在某些情况下,使用Angular$http.get或JQuery$.load编译通过XHR或Ajax请求加载的部分页面会引入错误。以我的场景为例,我正在使用KohanaPHP框架,因此我可以在服务器级别控制我的Web应用程序的模块化。像往常一样,所有模板和页面都被分离到View中,将所有HTML、JS和CSS留在表示层上。这将为我在客户端处理上实现JavascriptMVW/MVC堆栈提供极大的灵active,因为我的Web应用程序严重依赖AJAX请求从后端应用程序获取数据。在我的场景中,我使

javascript - Angular 中的根元素是什么?

我写了这样一个指令:app.directive('headersort',function(){return{restrict:'E',scope:{sortBy:'=',title:'='},template:'{{title}}',replace:true,link:function(scope,element,attributes){scope.sortBy=attributes.sortBy;scope.title=attributes.title;}};});我是这样使用它的:我想要的是替换为Product.但是我收到一条错误消息:Templatemusthaveexactl

javascript - 不使用 JQuery 将 Masonry 添加到 Angular

我正在尝试让Masonry作为Angular指令工作,这在网上有部分记录,尽管我在以下代码中遇到以下问题:HTML代码:{{item.name}}{{button.text}}AngularDirective(指令)代码:'usestrict';angular.module('HomeCourtArenaApp').directive('masonry',function($parse){return{restrict:'AC',link:function(scope,elem,attrs){elem.masonry({itemSelector:'.masonry-item',colu

javascript - 在 promise 链中访问先前履行的 promise 结果

这个问题在这里已经有了答案:HowdoIaccesspreviouspromiseresultsina.then()chain?(17个答案)关闭7年前。在使用promises编码时,访问promises链中很久以前的数据的正确模式是什么?例如:do_A.then(do_B).then(do_C).then(do_D).then(do_E_WithTheDataComingFrom_A_And_C_OnlyWhen_D_IsSuccesfullyCompleted)我当前的解决方案:通过链传递单个JSON结构,并让每个步骤填充它。对此有何看法?

javascript - 有条件的 promise

在我的脚本中,我需要检索字典以将编码值转换为名称:$.ajax({//retrievedictionary}).done(function(dictionary){//convertencodedvaluesintonames}).done(function(){//runmyapplication});但是,有时字典已经被另一个应用程序加载,在这种情况下我不需要ajax调用:if(dictionary){//convertencodedvaluesintonames//runmyapplication}else{$.ajax({//retrievedictionary}).done(