我有一个场景,我希望在我的组件中同时使用ngOnChanges和ngDoCheck,但是我记得前段时间在 angular 文档中一次只能使用其中一个。
虽然我似乎再也找不到这些信息,但我认为它之前在本节的某个地方说过。
使用这两者是否安全,还是我需要实现我自己的ngOnChangesin版本DoCheck以避免大“不”?
考虑以下开关:
<Switch class="switch" formControlName="answer"></Switch>
Run Code Online (Sandbox Code Playgroud)
如果执行此操作,则仅在您尚未激活开关时才起作用,此后即使开关未激活,背景色也将始终相同:
.switch[checked=true] {
background-color: #FE4A49;
color: #FE4A49;
}
Run Code Online (Sandbox Code Playgroud)
如果我这样做:
.switch {
background-color: #FE4A49;
color: #FE4A49;
}
Run Code Online (Sandbox Code Playgroud)
这样,无论状态如何,背景都将始终相同。
将开关与angular的模型绑定一起使用时,样式设置开关的正确方法是什么?
我有这个功能可以为用户设置自定义声明:
export const setUserClaims = functions.https.onRequest((req, res) => {
return admin.auth().setCustomUserClaims(req.body.uid, req.body.claims);
});
Run Code Online (Sandbox Code Playgroud)
我只希望此功能可供超级管理员用户使用,即包含{admin: true}.
因此admin,例如可以通过调用此函数为支持人员设置用户声明。
我一直在四处寻找,但我没有找到一个 100% 健壮和安全的明显答案。
我怎样才能做到这一点?
我的下面有一个奇怪的边距GridView:
该图像来自 IOS 模拟器,以下是它在 Android 上较小屏幕上的外观,其中边距似乎消失或小很多:
这是代码:
Column(
children: [
GridView.count(
shrinkWrap: true,
crossAxisCount: 8,
children: tiles
),
Text('mamma')
]
)
Run Code Online (Sandbox Code Playgroud)
网格 ( tiles) 中的每个元素都是一个EmptyTile小部件:
class EmptyTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: bgColor,
border: Border.all(color: borderColor)
)
);
}
}
Run Code Online (Sandbox Code Playgroud)
我实在想不通这个margin到底是什么,从哪里来,是有什么关系shrinkWrap还是别的什么。
我怎样才能去掉这个边距?
编辑:
根据要求,这里是全屏图像,没有简化的示例。
苹果系统:
安卓:
我不明白为什么我的orderBy过滤器根本不起作用,我查看了每一个奇怪的解决方案,所有的解决方案都指向一个事实,即它是ng-repeat在对象的对象而不是对象数组上运行。但我的是一个对象数组,如下所示:
[Object, Object, Object]
0: Object
$$hashKey: "object:19"
dataLink: ""
id: "633"
name: "My first graph"
order: 1
parentTarget: ""
presenceLink: ""
size: 12
span: 1
subType: 1
type: 1
__proto__: Object
1: Object
$$hashKey: "object:20"
dataLink: ""
id: "634"
name: "My second graph"
order: 2
parentTarget: ""
presenceLink: ""
size: 6
span: 1
subType: 1
type: 3
__proto__: Object
2: Object
$$hashKey: "object:21"
dataLink: ""
id: "635"
name: "My third graph but in front"
order: …Run Code Online (Sandbox Code Playgroud) 我正在制作电子邮件模式,但实际提出请求时遇到问题http.post。问题是post()在子组件中执行,这意味着this.postUrl函数实际运行时未定义。如何确保子组件可以访问this.postUrl而不将其作为输入传递给它?我不想通过输入传递它的原因是子组件也在其他地方使用,使得它过于postUrl具体而无法用作输入,因为它只会在这种情况下使用。
@Component({
selector: 'modal-email',
templateUrl: './app/assets/scripts/modules/modal/templates/modal-email/modal-email.component.html',
styleUrls: ['./app/assets/scripts/modules/modal/templates/modal-email/modal-email.component.css'],
inputs: [
'model',
'postUrl',
'header',
'text'
],
directives: [FormInputWithButtonComponent],
providers: [Http, HTTP_PROVIDERS]
})
export class ModalEmailComponent {
constructor(private _http: Http) {
}
post() {
// this.postUrl becomes undefined, this.model is defined since it also lives in the child component
console.log(this.postUrl, this.model);
this._http.post(this.postUrl, {email: this.model})
.map(res => res.json())
.subscribe(
data => this.data = data,
err => console.log(err)
)
}
}
Run Code Online (Sandbox Code Playgroud)
ModalEmailComponent像这样使用:
<modal-email …Run Code Online (Sandbox Code Playgroud) 我有一个需要发出值的组件,但是我不能为上帝的爱弄清楚为什么在调用它时@Output()总是存在undefined它。我在其他组件中具有完全相同的代码,并以相同的方式触发它,但是在这种情况下它只是不想工作。
我在这里做错什么吗?
export class DropdownOptionsSingleComponent implements AfterViewInit {
@Input() current: any;
@Output('currentChange') onCurrentChange: EventEmitter<any> = new EventEmitter();
private isOpen: boolean = false;
constructor(private _globals: GlobalVariablesService, private _elementRef: ElementRef) {
this.ns = _globals.ns;
document.addEventListener('click', (e) => {
// If the clicked element is not the component element or any of its children, close the dropdown
if (_elementRef.nativeElement !== e.target && !_elementRef.nativeElement.contains(e.target)) {
this.isOpen = false;
}
});
}
ngAfterViewInit() {
let list = this._elementRef.nativeElement.getElementsByClassName(this.ns + '-dos-list')[0];
let …Run Code Online (Sandbox Code Playgroud) 正如标题所解释的那样,当router对象在subscribe成员内部被调用时,该对象变得不确定.
我来告诉你一些代码:
export class AuthComponent implements OnInit {
password = '';
email = '';
constructor(
private _router: Router,
private authService: AuthService
) { }
sendLogin(): void {
this.authService.login(this.email, this.password)
.subscribe(function(token){
console.log("Success Response" + token)
this.token = token
// TOKEN Here is good
// now I want to change my page, but
// _router -> undefined
this._router.navigate(['/dashboard']);
},
error => console.log(error));
}
Run Code Online (Sandbox Code Playgroud)
sendLogin()提交表单时调用该方法.表格中的每个变量都很好.
这个过程subscribe完美,但后来
this._router.navigate(['/dashboard']);
给了我:
EXCEPTION:无法读取undefined的属性'navigate'
有任何想法吗 ?
angular2-routing angular2-services angular2-observables angular
I got this grid with each square's index showing in the middle (0-63):
Then I have a function which needs to return the row number when I pass it an index.
The row number can be between 0-7.
Function that should do this, with a poor attempt at retrieving the row number currently inside it:
function (index) {
return Math.floor(index / 7);
}
Run Code Online (Sandbox Code Playgroud)
Example outputs (index -> row output):
0 -> 0
5 -> 0
7 -> 0
8 -> …