小编Jus*_*iar的帖子

Angular 8 - 如何使用 Promise 和 Async/Await

我一直在尝试使用教程,但似乎无法弄清楚如何使用 Promise 或异步等待。

我有一个 http GET 请求,我想在返回之前等待 API 的结果。返回 null 因为函数在 GET 发生之前返回。

获取

get_UserAccess(practiceId: number, userId: number): UserAccess {
    var d: UserAccess;

    this.httpclient.get(this.URL).subscribe.(data => {
      d = data as UserAccess;
    });

    return d; //Keeps returning as null
Run Code Online (Sandbox Code Playgroud)

调用组件

var userAccess = this.dataService.get_UserAccess(this.practice.practiceId, this.users[i].userId);
this.loadAccess(userAccess);
Run Code Online (Sandbox Code Playgroud)

我已经尝试将 await 和 async 标签添加到 get 请求中,但我不确定如何处理它返回给调用组件的承诺。

async-await angular-promise angular

7
推荐指数
2
解决办法
3万
查看次数

比较表示日期的整数

我正在努力确定一个日期是否在另一个日期的 30 天内。使这变得棘手的是日期由整数表示。所以如果我有:

int year = 1990; int month = 1; int day = 1;
Run Code Online (Sandbox Code Playgroud)

如果将其与以下内容进行比较,我如何正确返回 true:

int year = 1989; int month = 12; int day = 31
Run Code Online (Sandbox Code Playgroud)

目前我正在使用DateTime.DaysInMonth(year, month)但不确定如何在比较中应用它。

c# date date-arithmetic

2
推荐指数
1
解决办法
52
查看次数

Ada-提出了Constraint_error:“值:

我正在尝试使用Integer'Value将字符串转换为Integer。这对于文件的第一个循环工作正常,但是之后我得到了一个错误的'value输入(提高了Constraint_Error。我希望有人可以向我展示我的方式的错误,以便可以将字符串转换为整数)。每个循环。

WITH Ada.Text_IO, Ada.Integer_Text_IO;
USE Ada.Text_IO, Ada.Integer_Text_IO;

PROCEDURE Isbntest IS

  FUNCTION Strip(The_String: String; The_Characters: String)
        RETURN String IS
     Keep: ARRAY (Character) OF Boolean := (OTHERS => True);
     Result: String(The_String'RANGE);
     Last: Natural := Result'First-1;
  BEGIN
     FOR I IN The_Characters'Range LOOP
        Keep(The_Characters(I)) := False;
     END LOOP;
     FOR J IN The_String'RANGE LOOP
        IF Keep(The_String(J)) THEN
           Last := Last+1;
           Result(Last) := The_String(J);
        END IF;
     END LOOP;
     RETURN Result(Result'First .. Last);
  END Strip;


  Input: File_Type := Ada.Text_IO.Standard_Input;

BEGIN

   WHILE NOT End_of_File(Input) LOOP
     DECLARE 
     Line : …
Run Code Online (Sandbox Code Playgroud)

arrays string ada

0
推荐指数
1
解决办法
327
查看次数