import { Injectable } from '@angular/core';
@Injectable()
export class SpinnerService {
private _selector = '#spinner';
show() {
console.log(this._selector); // #spinner
$(this._selector).show();
}
hide() {
console.log(this._selector); // undefined
$(this._selector).hide();
}
}
第一次调用的是show函数,第二次调用的是hide函数。这个服务只提供到了根模块的providers中,是在惰性加载模块的组件中调用的函数
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这个做法是不可取的,这类似ng1的写法的,推荐的做法如下:
在你的模板文件(即
template.html)中使用结构型指令*ngIf绑定条件变量condition:在你的
component.ts文件里定义如下变量:在这里控制变量
condition的trueorfalse即可控制模板的显示和移除。注意,我这里说的是 移除 而不是 隐藏 ,原因你看看这里,这也是一份中文API,请善用。希望你能顺利解决问题 :)