我正在我的Angular 2应用程序中构建一个搜索框,尝试在点击"Enter"时提交值(表单不包含按钮).
模板
<input type="text" id="search" class="form-control search-input" name="search" placeholder="Search..." [(ngModel)]="query" (ngSubmit)="this.onSubmit(query)">
Run Code Online (Sandbox Code Playgroud)
使用简单的onSubmit函数进行测试......
export class HeaderComponent implements OnInit {
constructor() {}
onSubmit(value: string): void {
alert('Submitted value: ' + value);
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,ngSubmit似乎不起作用.那么解决这个问题的'Angular 2方式'是什么?(最好没有像隐藏按钮这样的黑客)
我正在构建一个Angular 2应用程序,它有一个侧导航栏,用于宽度超过500的屏幕,以及一个底部导航栏,用于宽度小于500的屏幕.现在我试图为侧栏指定20%的宽度,80 %到应用内容.
我遇到的问题是路由器插座内容(即实际的应用程序)占用了页面的整个宽度而不是80%.它似乎忽略了我试图给它的任何造型.我们不应该直接设置路由器插座的样式吗?或者也许有一种更好的方式让我俯瞰?
app.component.ts
import { Component, HostListener } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<div class="container-fluid">
<nav *ngIf="this.window.innerWidth > 500"></nav>
<router-outlet style="width:80%;float:right;"></router-outlet>
<nav *ngIf="this.window.innerWidth < 500"></nav>
`,
styleUrls: ['app/app.component.css']
})
export class AppComponent {
window = [];
ngOnInit(): void {
this.window.innerWidth = window.innerWidth;
}
@HostListener('window:resize', ['$event'])
onResize(event) {
this.window.innerWidth = event.target.innerWidth;
console.log(this.window.innerWidth);
}
}
Run Code Online (Sandbox Code Playgroud) 考虑Python中的以下实例行为.
def change(elements):
elements[0] = 888
elements = [-3, -1, -2, -3, -4]
print(elements[0])
numbers = [1, 4, 5]
print(numbers[0])
change(numbers)
print(numbers[0])
print(numbers)
Run Code Online (Sandbox Code Playgroud)
下面的Python代码段打印出来
1
-3,
888
[888,4,5]
Run Code Online (Sandbox Code Playgroud)
不应该打印
1,
-3,
-3,
[-3,-1,-2,-3,-4]
Run Code Online (Sandbox Code Playgroud)
为什么列表中的元素会被成功覆盖,而不是整个列表对象?
I have a huge bucket of S3files that I want to put on HDFS. Given the amount of files involved my preferred solution is to use 'distributed copy'. However for some reason I can't get hadoop distcp to take my Amazon S3 credentials. The command I use is:
hadoop distcp -update s3a://[bucket]/[folder]/[filename] hdfs:///some/path/ -D fs.s3a.awsAccessKeyId=[keyid] -D fs.s3a.awsSecretAccessKey=[secretkey] -D fs.s3a.fast.upload=true
Run Code Online (Sandbox Code Playgroud)
However that acts the same as if the '-D' arguments aren't there.
ERROR tools.DistCp: Exception encountered
java.io.InterruptedIOException: doesBucketExist on [bucket]: com.amazonaws.AmazonClientException: …Run Code Online (Sandbox Code Playgroud) 为什么 IntelliJ 抱怨它无法解析以下代码片段中的符号“字段”?
val condition: String = "aa"
if (condition == "aa") {
val fields: Int = 2
} else if (condition == "bb") {
val fields: Int = 3
} else if (condition == "cc") {
val fields: Int = 4
}
var g = 1
while (g < fields) {
//do something
g = g + 1
}
Run Code Online (Sandbox Code Playgroud) 以下代码段在'fields.size'处失败:"值大小不是Any的成员".为什么"字段"不是"列表"类型(正如我所料)?
val condition = "a"
val fields =
if (condition == "a") {
List(1,2)
} else if (condition == "b") {
List(1,2,3)
} else if (condition == "c") {
List(1,2,3,4)
}
var g = 1
while (g < fields.size) {
//do something
g = g + 1
}
Run Code Online (Sandbox Code Playgroud)