某个地方读了这个例子:
return new Promise( (resolve, reject) => {
fs.readFile(file, (err, data) => {
if (err) reject(err)
return resolve(data)
})
})
Run Code Online (Sandbox Code Playgroud)
但我通常这样做:
return new Promise( (resolve, reject) => {
fs.readFile(file, (err, data) => {
if (err) reject(err)
resolve(data)
})
})
Run Code Online (Sandbox Code Playgroud)
有区别吗?
如果我的angular2应用程序看起来像这样,并且顶部的金发女郎将在右中间与姜谈话,他们应该组织一个派对吗? 
发出事件,使用输入输出 - 这是angular2方式?数据应该从子节点传递到父节点到根节点,然后从父节点传递到子节点到点?我是新来的,我经常想要一些全局对象,我可以保留一些所有组件都需要知道的信息.当数据在该全局对象中发生变化时,它应该在它注入的所有其他服务和组件中神奇地改变.例如用户登录/注销,或者如果他点击按钮等等.
import {Injectable} from 'angular2/core';
@Injectable()
export object Globals {
logged: false,
showThatDiv: true
}
Run Code Online (Sandbox Code Playgroud)
但我在某处读到它是Angular1,而不是Angular2方式.这样对吗?或者我错了?它看起来不像全球汤,只是全球国家的对象.
例如,现在我有这样的结构:
|-root
|-google api component
|-google auth
|-youtube api
|-playlists
|-video
|-myComponent
|-sub1
|-sub2
|-sub3
|...
Run Code Online (Sandbox Code Playgroud)
mySub1组件需要知道用户是否已记录,如果是,则显示(*ngIf)sub2中的某个div.或者从mySub3组件调用googleAuth服务中的checkGauth().从mySub2组件添加视频到YouTube播放列表和onAdded在sub2中显示结果,或从sub3创建新播放列表并在sub2上显示.很多变种.
我厌倦了为所有这些编写代码.它使它更复杂.有时候想着这样做:
|-root
|-google api component
|-google auth
|-youtube api
|-playlists
|-video
|-myComponent
|-sub1
|-sub2
|-sub3
|...
Run Code Online (Sandbox Code Playgroud) 我想了解process.stdin.
例如 - 我需要在控制台中显示数组元素.我应该允许用户选择将显示哪个元素.
我有代码:
var arr = ['elem1','elem2','elem3','elem4','elem5'],
lastIndx = arr.length-1;
showArrElem();
function showArrElem () {
console.log('press number from 0 to ' + lastIndx +', or "q" to quit');
process.stdin.on('readable', function (key) {
var key = process.stdin.read();
if (!process.stdin.isRaw) {
process.stdin.setRawMode( true );
} else {
var i = String(key);
if (i == 'q') {
process.exit(0);
} else {
console.log('you press ' +i); // null
console.log('e: ' +arr[i]);
showArrElem();
};
};
});
};
Run Code Online (Sandbox Code Playgroud)
当我第二次输入数字时,为什么"i"为空?如何正确使用"process.stdin.on"?
我正在为我的 Flutter 应用程序创建 Firebase 远程配置实验和 A/B 测试。为了验证测试设备上的实验,我需要获取Firebase installation auth token与每个 Firebase 安装关联的实验。
如何在“Flutter-way”中获取这个token?在文档中,有办法为 Swift、Kotlin 等获取它。但不适用于 Dart/Flutter。
在我的应用程序中,我firebase_core安装了软件包,FirebaseOptions 有一堆 id:
this.apiKey,
this.appId,
this.messagingSenderId,
this.projectId,
this.measurementId,
Run Code Online (Sandbox Code Playgroud)
但没有 Firebase安装身份验证令牌。
一种是通过事件,另一种是通过调用方法。我试图在我的应用程序中实现聚合模式。
我有AuthService,在这里我处理auth结果并发出事件。
if (auth) { this.eAuth.emit(true) } else { this.eAuth.emit(false) }
Run Code Online (Sandbox Code Playgroud)
我可以订阅AuthComponent
_authService.eAuth.subscribe( (isAuth) => this.handleAuthResult(isAuth) )
Run Code Online (Sandbox Code Playgroud)
而且效果很好。但是AggregateService也需要了解这一点,并将此信息广播到UserService,LoadDataService等。
怎么做?
upd:我的AggregateService没有组件,我已经向其中注入AuthService。
我试图在我的ionic2应用程序中实现google auth.我需要它在浏览器中工作.所以,我安装:
npm install --save @types/gapi
npm install --save @types/gapi.auth2
Run Code Online (Sandbox Code Playgroud)
有两个警告:
npm WARN可选SKIPPING OPTIONAL DEPENDENCY:fsevents@^1.0.0(node_modules\chokidar \node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY:不支持的fsevents@1.0.15平台:想要{"os":"darwin","arch":"any"}(当前:{"os":"win32","arch": "64"})
在node_modules文件夹中我有gapi和gapi.auth2文件夹,但我有打字稿错误:找不到名称'gapi',transile失败.
我安装了
npm install typings -g
typings install dt~gapi --global --save
typings install dt~gapi.auth2 --global --save
Run Code Online (Sandbox Code Playgroud)
还是有同样的错误:找不到名字'gapi',transile失败了
我的代码:
auth2: any;
login() {
gapi.load('auth2', () => {
this.auth2 = gapi.auth2.init({
client_id: 'xxxxxxxxx.apps.googleusercontent.com',
scope: 'https://www.googleapis.com/auth/userinfo.email'
});
});
};
Run Code Online (Sandbox Code Playgroud)
我的package.json:
"@angular/core": "2.2.1",
"ionic-angular": "2.0.0-rc.4",
"ionic-native": "2.2.11",
"rxjs": "5.0.0-beta.12",
"typescript": "2.0.9"
Run Code Online (Sandbox Code Playgroud) typescript ionic-framework google-oauth2 ionic2 typescript2.0
我正在编写扩展 statelessWidget 的类,它的构建方法返回Text()小部件。我需要将来自Map<dynamic, dynamic>. 为什么我不能spread像这样使用运算符
final Map textOptions;
final String text;
build(BuildContext context) {
return Text(text, ...textOptions)
}
Run Code Online (Sandbox Code Playgroud) 请阅读这个区块片段:
if (event is TapVariant) {
final bool isVariantCorrect = (correctVariantIndex == event.index);
if (isVariantCorrect) {
yield CorrectVariant();
} else {
yield IncorrectVariant();
Future.delayed(Duration(seconds: 1), () {
yield CorrectVariant();
});
}
}
Run Code Online (Sandbox Code Playgroud)
我需要从嵌套函数中产生 CorrectVariant。
我是这样解决的:
yield IncorrectVariant();
await Future.delayed(Duration(seconds: 1), () {});
yield CorrectVariant();
Run Code Online (Sandbox Code Playgroud)
但我很好奇。