我是Angular2的新手,我有一点问题:
在我的Login-Component-HTML中,我有两个复选框,我希望以双向数据绑定方式绑定到Login-Component-TypeScript.
这是HTML:
<div class="checkbox">
<label>
<input #saveUsername [(ngModel)]="saveUsername.selected" type="checkbox" data-toggle="toggle">Save username
</label>
</div>
Run Code Online (Sandbox Code Playgroud)
这是Component.ts:
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Variables } from '../../services/variables';
@Component({
selector: 'login',
moduleId: module.id,
templateUrl: 'login.component.html',
styleUrls: ['login.component.css']
})
export class LoginComponent implements OnInit {
private saveUsername: boolean = true;
private autoLogin: boolean = true;
constructor(private router: Router, private variables: Variables) { }
ngOnInit() {
this.loginValid = false;
// Get user name from local storage …Run Code Online (Sandbox Code Playgroud) 在C#中,可以使用命名参数调用给定方法:
myObject.SetSize(width: 100, height: 100);
它们似乎主要用于满足可选参数,但是......它们还极大地提高了方法调用站点的可读性.它还可以保护您免受错误的参数规范.
从我能够收集的内容来看,如果我希望从TypeScript中的 "声明性调用站点"中受益,我最好使用基于给定接口的"参数对象".
interface SizeArguments {
width: number;
height: number;
}
export class MyClass {
setSize(args: SizeArguments) {
/* Set size... */
}
}
new MyClass().setSize({ width: 100, height: 100 });
Run Code Online (Sandbox Code Playgroud)
适合我!但对于C#中如此微不足道的事情来说,这仍然是相当多的工作.这种方法是我现在能做的最好吗?还是我从根本上监督一些事情?
我有两个Typescript反应模块:moduleA和moduleB.
我试图用一个部件Button.tsx从moduleA通过导出Button.tsx在moduleB使用参照本组件moduleA.
这是我遵循的步骤:
moduleA.moduleA.moduleB.moduleA在moduleB使用npm install ../moduleA.然后,我在引用Button组件moduleB,moduleA使用:
import { Button } from "moduleA";
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
ERROR in C:\Users\VaibhavPC\Projects\moduleb\src\Start.tsx
./src/Start.tsx
[tsl] ERROR in C:\Users\VaibhavPC\Projects\moduleb\src\Start.tsx(2,24)
TS2307: Cannot find module './moduleA'
Run Code Online (Sandbox Code Playgroud)
这是我package.json的moduleA:
{
"name": "moduleA",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "react-scripts …Run Code Online (Sandbox Code Playgroud) 我有什么方法可以在Angular 2应用上使用Google Adsense广告吗?
我在Angular 2组件中看到了这个Google AdSense广告?但答案实际上并不适合我.我看到的是空格而不是广告.我想要放置的是响应式广告.我完全按照上面问题的答案说,用这个模板代码:
<div class="text-center">
<ins class="adsbygoogle" style="display:inline-block;height:150px"
data-ad-client="my ca-pub" data-ad-slot="my ad slot"></ins>
</div>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我想使用Spring Application的GET请求在Angular应用程序中显示HashMap.我试过这个:
春天代码:
@GetMapping("gateways")
public ResponseEntity<?> getGateways() {
Map<Integer, String> list = new HashMap<>();
list.put(1, "Bogus");
return ok(list.put);
}
Run Code Online (Sandbox Code Playgroud)
角度服务:
getContractGatewaysList(): Observable<Array<ContractGatewaysList>> {
return this.http.get<Array<ContractGatewaysList>>(environment.api.urls.contracts.getContractGateways);
}
Run Code Online (Sandbox Code Playgroud)
角度成分:
gateways: ContractGatewaysList[];
this.contractService.getContractGatewaysList()
.subscribe(value => {
if (value != null) {
this.gateways = value;
}
});
Run Code Online (Sandbox Code Playgroud)
接口:
export interface ContractGatewaysList {
id: number;
name: string;
}
Run Code Online (Sandbox Code Playgroud)
HTML代码:
<div class="form-group gateway">
<div class="input-group-prepend">
<label for="merchant_id">Gateway</label>
</div>
<select class="custom-select" name="gateway" [(ngModel)]="contract.gateway" id="gateway" required>
<option selected>Please Select...</option>
<option [value]="gateway.id" *ngFor="let gateway of gateways">{{ gateway.name }}</option>
</select> …Run Code Online (Sandbox Code Playgroud) 假设我们从这开始:
var foo = {n:1};
var bar = foo;
在JavaScript中,执行以下分配的顺序是:
foo.x = foo = {n:2};
当我查找答案时,我发现了几个似乎表明任务从右到左发生,例如:
foo = {n:2};
foo.x = foo;
在这种情况下,我们期望:
console.log(foo) //{n:2, x:Object} - (a circular reference back to foo)
然而,当我实际执行此操作时,我在控制台中看到的内容表明分配实际上是从左到右:
console.log(foo) //{n:2}
console.log(bar) //{n:1, x:Object}
- > {n:1} obj获取'x'属性,foo被重新分配给新对象{n:2}
当一行中有多个作业时,有人可以为我澄清操作的顺序吗?
此外,将上述场景与以下情况区分开来的基本规则是什么: 一行中的多个变量赋值
上述问题中的一些答案声称原语的分配是在左边进行的......
错误说没有匹配的函数要求push_back().
我包括<vector>所以我不明白为什么会发生这种错误.如果你还可以告诉我如何接受一个字符串并将其存储到一个非常有用的矢量中!
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> list;
char input;
while(cin>>input)
{
list.push_back(input);
}
for(int i=0;list.size();i--)
{
cout<<list[99-i];
}
}
Run Code Online (Sandbox Code Playgroud) #include < stdio.h >
#include < conio.h >
#define BILMAX 10
int main()
{
int num[BILMAX],i;
printf("insert 10 number and separated by space:\n");
for (i = 0;i<10;i++)
{
scanf("%d",&num[i]);}
printf("\n\nEven Number : \n");
for(i = 0; i < 10; i++)
{
if(num[i] % 2==0)
printf("%d",num[i]);
}
printf("\n\nOdd Number : \n");
for(i = 0;i < 10; i++)
{
if(num[i] % 2 !=0)
printf("%d",num[i]);
}
getch();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的输出是这样的
插入10个数字并用空格分隔:
1 2 3 4 5 6 7 8 9 10
偶数: …