小编Man*_*dha的帖子

TemplateRef 中未定义 ElementRef

在 Angular 中试验 ElementRef、TemplateRef、ViewRef 和 ViewContainerRef。我已经创建了一个 HTML 模板,我想从那里创建一个视图并将该视图传递给 ViewContainerRef 但它不起作用

模板代码

template: `
  <ng-container #vc></ng-container>
  <ng-template #mytmpl>
    <div>Name: <input type="text" name="name" /> </div>
    <div>Gender: 
      <select  name="gender" >
        <option>Male(1)</option>
        <option>Female(2)</option>
      </select>
    </div>
    <div>About you: <textarea ></textarea></div>
    <div>Married: <input type="checkbox" /></div>      
    <div>Children:     
      <ng-container *ngFor = "let option of this.selectOptions">
        <input  type="radio" [id]="option" name="children" [value]=option [(ngModel)]="this.children"/> {{option}}
      </ng-container>
   </div>
   <p>Some para</p>
   <p>Para with span <span>Inside span</span></p>
  </ng-template>
`
Run Code Online (Sandbox Code Playgroud)

在课堂上,我访问模板和视图容器

@ViewChild('vc',{read:ViewContainerRef}) v:ViewContainerRef;
@ViewChildren("mytmpl") myTemplateList:TemplateRef<any>;
Run Code Online (Sandbox Code Playgroud)

我使用以下代码来创建视图

ngAfterViewInit(){
  let elementRef = this.myTemplateList.elementRef
  let view = this.myTemplateList.createEmbeddedView(null) …
Run Code Online (Sandbox Code Playgroud)

angular

5
推荐指数
1
解决办法
1万
查看次数

如何在 OpenAPI 3.0 的架构中使用 $ref?

我想schema在 OpenAPI 3.0 API 定义中将以下 JSON 表示为 a :

{
get-question: {
  question-id:string
  }
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经写了:

{
get-question: {
  question-id:string
  }
}
Run Code Online (Sandbox Code Playgroud)

但我在 Swagger 编辑器中收到这些错误:

Schema error at components.schemas['GetQuestion']
should have required property '$ref'
missingProperty: $ref
Jump to line 79
Schema error at components.schemas['GetQuestion']
should match exactly one schema in oneOf
Jump to line 79
Schema error at components.schemas['GetQuestion'].properties['get-questions']
should have required property '$ref'
missingProperty: $ref
Jump to line 81
Schema error at components.schemas['GetQuestion'].properties['get-questions']
should match exactly one …
Run Code Online (Sandbox Code Playgroud)

openapi

5
推荐指数
1
解决办法
5058
查看次数

在 Mockito 单元测试中抛出异常时,Future 的 .recover 不会被调用

以下代码返回一个 Future。

val findUserFuture: Future[Option[User]] = userRepo.findOne(userKeys) 
Run Code Online (Sandbox Code Playgroud)

然后我处理未来

findUserFuture.flatMap {....}
.recover{...}
Run Code Online (Sandbox Code Playgroud)

fineOne返回FutureFuturewraps 调用getOneById

def findOne(userKeys:UserKeys):Future[Option[User]] = {
    Future{
      //val loginInfo:LoginInfo = LoginInfo(userKeys.providerID,userKeys.authProvider)
      val userOption:Option[User] = getOneById(userKeys)
      userOption
    }
  }
Run Code Online (Sandbox Code Playgroud)

我想如果失败Future返回将调用recover ,findOne即抛出异常。所以我通过getOneById抛出异常来模拟。

when(mockUserRepository.findOne(userKeys)).thenReturn(Future(Some(user)))
      when(mockUserRepository.getOneById(userKeys)).thenThrow(classOf[RuntimeException]) //simulating database error
Run Code Online (Sandbox Code Playgroud)

但是单元测试不会抛出异常,测试会使用 value 进行Future(Some(User))

我也尝试从引发异常findOne-when(mockUserRepository.findOne(userKeys)).thenThrow(classOf[RuntimeException])但测试用例以下两个打印停止,.recoverFuture不叫

java.lang.RuntimeException was thrown.
java.lang.RuntimeException
Run Code Online (Sandbox Code Playgroud)

scala mockito scalatest

5
推荐指数
1
解决办法
386
查看次数

使用 Minikube kubectl 创建部署时未知的映像标志

我在使用onunknown image flag创建部署时遇到了问题。为什么?minikubewindows 10 cmd

C:\WINDOWS\system32>minikube kubectl create deployment nginxdepl --image=nginx
Error: unknown flag: --image
See 'minikube kubectl --help' for usage.

C:\WINDOWS\system32>
Run Code Online (Sandbox Code Playgroud)

kubernetes kubectl minikube

5
推荐指数
1
解决办法
5190
查看次数

如果其项目是 Angular 组件,则 CSS-Grid 不起作用

我有一个工作代码(在 HTML/CSS 网格中),它由css-grid3 行 2 列组成。第一行是导航(跨越所有列),中间是内容(没有跨越所有列),最后一行是页脚(跨越所有列)。

.body__div--background {
  background: linear-gradient(45deg,#33b1f8 37%,#6e90f6 100%); /*syntax linear-gradient(direction, color1 limit, color2 limit)*/
  color:#555555;
  font-family: Verdana;
  line-height:1.5;
  font-size: 11px;
  letter-spacing: 0.25px;
}

.css-grid-container{
  height:100vh; /*???*/
  display: grid;
  grid-gap:20px;
  grid-template-columns: 1fr 1fr;  /* 2columns*/
  grid-template-rows: auto 15fr 1fr; /* 3 rows. Auto takes height of navigation, remaining is divided into 2 rows, middle row (content) is 15 times larger than the 3rd row (footer).*/

}
Run Code Online (Sandbox Code Playgroud)

css元素放在网格中的适当位置是

.css-grid-item__nav{
  grid-column: 1 / -1; //nav …
Run Code Online (Sandbox Code Playgroud)

css css-grid angular

4
推荐指数
2
解决办法
3801
查看次数

什么是 Angular 中组件的 Host 元素

如果我有 Component 类

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
}
Run Code Online (Sandbox Code Playgroud)

和 index.html 是

<div>
<my-app></my-app>
</div>
Run Code Online (Sandbox Code Playgroud)

组件的宿主元素是什么?会是<div>还是<my-app>?如果是<my-app>,有没有办法从 访问<div>(的父AppComponentAppComponent

angular6

4
推荐指数
1
解决办法
3248
查看次数

我可以在不使用 sbt 创建项目的情况下获得 Scala REPL吗

我想安装Scala REPLwindows10. 我在互联网上环顾四周,但我似乎找不到如何获取scala二进制文件和REPL. 这些链接似乎建议我使用Intellijsbt。如果我得到 sbt,创建项目的方式是例如sbt new hello,它似乎做了很多事情(见下文)!

问题 1 - 我怎样才能得到REPL. 我不想创建项目,我只需要一个命令行工具来练习编写表达式。

问题 2-安装后sbt,我安装了,sbt new hello并且在命令行中看到结果让我不知所措。下面在做什么sbt以及为什么项目仍未创建(请参阅最后的错误,Template not found for: hello?我已截断输出以保持在字数限制内

C:\Users\manuc\Documents\manu>mkdir scala_programs

C:\Users\manuc\Documents\manu>cd scala_programs

C:\Users\manuc\Documents\manu\scala_programs>sbt new hello
"about to robocopy"

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows
-------------------------------------------------------------------------------

  Started : 14 September 2018 09:43:43
   Source : C:\Program Files (x86)\sbt\lib\local-preloaded\
     Dest : C:\Users\manuc\.sbt\preloaded\

    Files : *.* …
Run Code Online (Sandbox Code Playgroud)

scala sbt

4
推荐指数
1
解决办法
880
查看次数

我应如何检查Future不为空

以下代码返回Future

val findUserFuture: Future[Option[User]] = userRepo.findOne(userKeys) 
Run Code Online (Sandbox Code Playgroud)

然后我处理 Future

findUserFuture.flatMap {....}
.recover{...}
Run Code Online (Sandbox Code Playgroud)

我想recover如果flatMap抛出一个将被调用Exception。但是,如果findOne回报null呢?有没有一种Scala特定的方式来检查findUserFuture是不是null?我可以吗,if(findUserFuture != null)但我想知道是否Scala提供了一些不同的方法来检查nulls

scala

4
推荐指数
1
解决办法
119
查看次数

Scalatest 中是否有相当于 @Before 或 beforeEach 的东西

测试框架jasmine提供junit了在每次测试运行之前配置测试环境的方法。scalatest和中有类似的东西吗playspec

scalatest

4
推荐指数
1
解决办法
2935
查看次数

如何根据字符对字符串进行模式匹配?

在我的代码中,字符串应具有以下结构part1-part2-part3。不同的部分由隔开,-只能有3个部分。

到目前为止,我已经使用过的split方法,String并且可以检查返回的长度Array以验证结构:

val tagDetails: Array[String] = tag.split('-') //syntax of received tag is part1-part2-part3

if (tagDetails.length == 3) {
  val course: String = tagDetails(0)
  val subject: String = tagDetails(1)
  val topic: String = tagDetails(2)
  println("splitted tag " + course + ", " + subject + ", " + topic) 
} else {..}
Run Code Online (Sandbox Code Playgroud)

我该怎么做match呢?

scala

4
推荐指数
2
解决办法
54
查看次数

标签 统计

scala ×4

angular ×2

scalatest ×2

angular6 ×1

css ×1

css-grid ×1

kubectl ×1

kubernetes ×1

minikube ×1

mockito ×1

openapi ×1

sbt ×1