我试图将以下代码用于获取角度为2的窗口对象:
@Component({
selector: 'app-slider',
templateUrl: './slider.component.html',
styleUrls: ['./slider.component.css'],
providers: [
SliderService,
{ provide: "windowObject", useValue: window}
]
})
export class SliderComponent implements OnInit {
sliderList: Slider[] = [];
constructor( private _sliderservice:SliderService, @Inject("windowObject") private _window:window ) { }
Run Code Online (Sandbox Code Playgroud)
不幸的是它不起作用.
我试图将值推入数组,然后在视图中显示。一切工作正常,但我想添加自动递增编号。我在data.json文件中有以下数组
[
{"id":1,"name":"John","gender":"Male"},
{"id":2,"name":"Smith","gender":"Male"},
{"id":3,"name":"Linda","gender":"Female"},
{"id":4,"name":"Jerry","gender":"Female"}
]
Run Code Online (Sandbox Code Playgroud)
在user.service文件中
private JsonDirectory: string = "assets/data.json"
constructor(private _httpReference: Http){}
getUsers(){
return this._httpReference.get(this.JsonDirectory)
.map((responseReference:Response) => responseReference.json());
}
Run Code Online (Sandbox Code Playgroud)
在user.componenti中,我在pressEnter事件上将输入值推送到数组中,因为我只有一个输入值,所以我已经推送了,但是也有id,因此它应该自动递增。以下是我正在尝试的代码
UserArray = [];
constructor(private userService: UserService, private _location: Location){}
show_value: string = '';
OnPressEnter(show_value: string){
var inputValue = show_value;
this.show_value = show_value;
this.UserArray.push({"id":5,"name":inputValue });
}
Run Code Online (Sandbox Code Playgroud)
您可以看到id是静态的,我想使其动态。
<ul>
<li *ngFor="let userCourse of UserArray" (click)="onSelect(userCourse.name)">
<span>{{userCourse.id}}</span> | <a style="cursor:pointer;">{{userCourse.name}} </a>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Angular2 中发送 HTTP post 请求,但无法将标头设置为内容类型应用程序 JSON。
我的代码是:
login(url,postdata)
{
var headers = new Headers({'Content-Type': 'application/json'});
return this._http.post(url,JSON.stringify(postdata),this.headers)
.map(res => res.json())
}
Run Code Online (Sandbox Code Playgroud)
当我检查网络时,我发现 Content-Type 设置为文本/纯文本,因此服务器没有接收任何数据。任何建议将不胜感激。
import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { User } from '../account.interface';
import { AF } from '../angularfire.service';
@Component({
selector: 'app-account',
templateUrl: './account.component.html',
styleUrls: ['./account.component.less']
})
export class AccountComponent implements OnInit {
public error: any;
user: FormGroup;
onSubmit() {
console.log(this.user.value, this.user.valid);
}
currentUserDetails = [];
firstName: string = '';
lastName: string = '';
email: string = '';
phone: string = '';
bio: string = '';
userID: string = '';
constructor(private afService: …Run Code Online (Sandbox Code Playgroud) 我在 HashMap 的上下文中读过某处:
hashCode() allows sorting objects by their hash values, and then the Object#equals method only needs to be invoked when objects share the same hash value.
是否意味着最终调用 equals() 方法时,已经比较了 hashCode 并发现必然相等?这种情况有什么例外吗?
问题的第二部分:在 equals() 方法中检查两个对象的 hashCode() 是否有意义?
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof InternalObjectSerialized)) {
return false;
}
InternalObjectSerialized<?> inputObj = (InternalObjectSerialized<?>) obj;
if (!(Arrays.equals(this.bytes, inputObj.bytes))) {
return false;
}
// …Run Code Online (Sandbox Code Playgroud) $("#classesLink").click(function(event) {
$("#globalUserContent").children().slideUp("normal", function() {
$.ajax({
type: "POST",
url: "classes.php?token="+randString+"",
success: function (msg) {
$("#globalUserContent").html(msg);
},
error: function (msg) {
$("#globalUserContent").html(msg);
}
});
});
return false;
});
Run Code Online (Sandbox Code Playgroud)
我有上面的代码,当我点击.classesLink按钮并检查firebug请求时,它显示它被提交两次,它有什么问题吗?
我想在我的jsp页面中获取客户端的IP地址,并希望存储在我的数据库中.
我在Jsp页面中使用以下代码来填充IP地址,但它显示的是服务器IP地址.
<input type="hidden" name="ipaddress" value="<%=request.getRemoteAddr()%>"/>
Run Code Online (Sandbox Code Playgroud) public class EqualsTest {
public static <T> boolean equalTest(T o1, T o2) {
return o1.equals(o2);
}
public static void main(String[] args) {
EqualsTest et1 = new EqualsTest();
EqualsTest et2 = new EqualsTest();
System.out.println(et1.equals(et2));
System.out.println(equalTest(et1, et2));
}
public boolean equals(Object o) {
if (o instanceof EqualsTest) {
System.out.println("equals(Object)");
return true;
}
return false;
}
public boolean equals(EqualsTest et) {
System.out.println("equals(EqualsTest)");
return this.equals((Object)et);
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个简单的替换应用程序,用户输入一个字符串,该字符串被分为子串,然后每个字符替换一个数字.
我遇到的麻烦只是最后一组替换被采取行动,或者至少如果前两个正在工作它们被取消并返回"0".
因此,对于"abc"的输入,我需要输出"123"但是我得到"003",或者如果输入是"bcd",则输出应该是"234"但是我得到"004".
我哪里错了?
JButton button_1 = new JButton("Substitute");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String str = textField_1.getText();
String str0 = str.substring(0);
int val1 = 0;
if (str0.equalsIgnoreCase("a")) { val1 += 1; }
if (str0.equalsIgnoreCase("b")) { val1 += 2; }
if (str0.equalsIgnoreCase("c")) { val1 += 3; }
if (str0.equalsIgnoreCase("d")) { val1 += 4; }
String str1 = str.substring(1);
int val2 = 0;
if (str1.equalsIgnoreCase("a")) { val2 += 1; }
if (str1.equalsIgnoreCase("b")) { val2 += 2; }
if …Run Code Online (Sandbox Code Playgroud) 我真的不明白以下static块.我在使用方法和变量时理解static关键字,但我不确切知道下面代码中静态关键字的用途是什么.
static
{
sURIMatcher.addURI("contacts", "people", PEOPLE);
sURIMatcher.addURI("contacts", "people/#", PEOPLE_ID);
sURIMatcher.addURI("contacts", "people/#/phones", PEOPLE_PHONES);
sURIMatcher.addURI("contacts", "people/#/phones/#", PEOPLE_PHONES_ID);
sURIMatcher.addURI("contacts", "people/#/contact_methods", PEOPLE_CONTACTMETHODS);
sURIMatcher.addURI("contacts", "people/#/contact_methods/#", PEOPLE_CONTACTMETHODS_ID);
sURIMatcher.addURI("contacts", "deleted_people", DELETED_PEOPLE);
sURIMatcher.addURI("contacts", "phones", PHONES);
sURIMatcher.addURI("contacts", "phones/filter/*", PHONES_FILTER);
sURIMatcher.addURI("contacts", "phones/#", PHONES_ID);
sURIMatcher.addURI("contacts", "contact_methods", CONTACTMETHODS);
sURIMatcher.addURI("contacts", "contact_methods/#", CONTACTMETHODS_ID);
sURIMatcher.addURI("call_log", "calls", CALLS);
sURIMatcher.addURI("call_log", "calls/filter/*", CALLS_FILTER);
sURIMatcher.addURI("call_log", "calls/#", CALLS_ID);
}
Run Code Online (Sandbox Code Playgroud) java ×5
angular ×4
ajax ×1
android ×1
angular2-cli ×1
constructor ×1
equals ×1
hashcode ×1
hashmap ×1
header ×1
if-statement ×1
jquery ×1
jsp ×1
post ×1
typescript ×1