我很好奇这两个函数在Angular 4中有什么不同:
get currentIndex(): number {
return `Current Index is ${this.index}`;
}
public currentIndex(): number {
return `Current Index is ${this.index}`;
}
它们做的是完全一样的事情吗?如果是这样,他们什么时候会做一些不同的事情?
在文件a.js中
// a.js
let a = 1
Object.defineProperty(module, "exports", {
get() {
return a
},
set(v) {
a += 1
},
enumerable: true,
configurable: true,
})
在文件b.js中
// b.js
const a = require("./a")
console.log(a) // 1
a = 2 // a should now be 3
// Throws "Uncaught
我用的是角7,我想在打字稿中得到并设置变量
我的代码login.service.ts
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class LoginService {
public username:string;
public token:string;
public fullname:string;
constructor() { }
set setUser(val: string){
thi
我正在尝试创建一个抽象类,强制实现同时实现getter和setter。我正在遵循上描述的内容,但我一直收到
Traceback (most recent call last):
File "test.py", line 30, in <module>
test = B('bar')
TypeError: Can't instantiate abstract class B with abstract methods foo
即使我在B中实现了foo getter和setter。
下面是我的代码:
from abc import A
我正在构建一个Angular4项目,并使用IntelliJ。每当我创建一个新类时,然后添加getter、和setters。IDE向字段添加下划线。
由于IDE似乎自动识别了类型记录语法,但却以这种方式创建字段,这让我认为这是一种最佳实践,但我也读到了不应该这样做的文章。
IDE为什么要这样做?我应该允许它为一个角度的项目做这个吗?谢谢你的帮助!
在创建getter和setter之前
export class Test {
hello:string;
world:string;
}
在创建getter和setter之后
export class Test {
privat
如果我在父组件中应用了一个子组件(它使用了ControlValueAccessor),并且在子组件中应用了一些东西,那么一切都会相应地传递给父组件。
但是,如果我试图在父组件中写入某些内容,然后将其传递给子组件,则输入中没有可用的内容。我怎么才能解决这个问题?
首先要说明的是,这是首选的行为:
child string value = written in child
parent string value = written in child
但是,每当我在父输入中输入文本时,就会得到以下内容:
child string value = (empty)
parent string value
我为API的默认错误响应体创建了一个对象。因此,我创建了类,声明了构造函数和参数,并从lombok添加了@Getter和@Setter。
@Getter
@Setter
public class ResponseError {
private Date timestamp;
private int status;
private int code;
private String message;
public ResponseError(Date timestamp, int status, int code, String message)