我正在使用Angular 2并在使用observable时出现此错误Property '_body' does not exist on type 'Response'.代码如下
this.securitiesService.getMarketMovers()
.subscribe(data => {
console.log(JSON.parse(data._body))
});
Run Code Online (Sandbox Code Playgroud)
getMarketMovers函数就是这样的:
getMarketMovers() {
return this._http.get('...url address...')
}
Run Code Online (Sandbox Code Playgroud)
我试图设置data类型,any但这对我不起作用.代码工作,_body数据肯定有一个属性,但它仍然会抛出错误,我不能用这个错误构建.
任何帮助是极大的赞赏.
我想弄清楚Angular 2中的ngOnDestroy是在刷新时运行还是当有人离开页面时?
我的组件中有一个反应形式,我想touched在每个输入上设置属性等于true.我目前的代码是这样但它却引发了我的错误Cannot set property touched of #<AbstractControl> which has only a getter:
addressForm: FormGroup;
...
this.addressForm = this._fb.group({
street: ["", [<any>Validators.required]],
city: ["", [<any>Validators.required]],
state: ["", [<any>Validators.required]],
zipCode: ["", [<any>Validators.required]],
country: ["", [<any>Validators.required]]
});
...
for (var key in this.addressForm.controls) {
this.addressForm.controls[key].touched = true;
}
Run Code Online (Sandbox Code Playgroud)
如何设置touched每个输入的值true?
我有一个Web应用程序,前端是Angular2,后端是NodeJS.我希望允许客户使用Google身份验证器使其帐户更安全.
如何在我的网站中实施/使用Google身份验证器?我找不到要使用的API或要跟随的教程或要使用的任何库.我在哪里可以找到一些资源来做到这一点?
javascript google-authentication node.js two-factor-authentication
我正在使用AngularClass的Angular2 Webpack Starter,我最近开始使用量角器遇到一些错误,我不知道它们来自哪里.当我尝试构建时,我得到错误:
Module 'webdriver' has no exported member 'IButton',
Module 'webdriver' has no exported member 'IKey',
Module 'webdriver' has no exported member 'Locator'(约30倍),和用于会员相同的消息IErrorCode,IType,ILevelValues,ILevel,和其他一些部件.
我也得到错误:
Property 'Error' does not exist on type 'typeof error'
和
Property 'stacktrace' does not exist on type 'typeof webdriver'
只是一大堆错误,我不知道为什么他们现在突然出现或者他们来自哪里.有没有人碰到这个或知道如何解决这个问题?谢谢!
I have an app using the cors npm package as middleware. I have it set up like this:
if(process.env.NODE_ENV === 'production') {
var whitelist = ['http://mywebsite.com', 'https://mywebsite.com']
var corsOptions = {
origin: (origin, callback) => {
var originIsWhitelisted = whitelist.indexOf(origin) !== -1;
console.log('ORIGIN: ', origin); // => undefined
callback(originIsWhitelisted ? null : 'Bad Request', originIsWhitelisted)
},
credentials:true
}
app.use(cors(corsOptions));
}
Run Code Online (Sandbox Code Playgroud)
The origin parameter in my corsOptions is undefined. Why is this and how can I fix it?
在我的TS文件中,我正在selectedValsObj像这样动态地在对象上创建属性:
private selectValsObj: any = {};
setSelectedValsObj(sectionsArr) {
sectionsArr.forEach(section => {
section.questions.forEach(questionObj => {
if (questionObj.type === 'drop-down') {
this.selectValsObj[questionObj.questionId] = { selected: questionObj.answerDetails[0] };
}
})
});
}
Run Code Online (Sandbox Code Playgroud)
在我的HTML中,我想将[ngModel]我的输入绑定到该selectValsObj对象的属性。我已经尝试过了,但是没有运气:
<div *ngFor="let question of section.questions">
<div class="drop-down-question" *ngIf="question?.type === 'drop-down'">
<select class="q-select"
[(ngModel)]="selectValsObj[questionId].selected" // <== doesnt work either**
// [(ngModel)]="selectValsObj[{{ questionId }}].selected" // <== doesnt work**
name="answerForQuestion{{ question?.questionId }}">
<option *ngFor="let answer of question?.answerDetails"
[ngValue]="answer">
{{ answer?.value }}
</option>
</select>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
如何ngModel …
将我的 Amazon S3 密钥/机密存储在私有 Github 存储库中是否安全?我知道公共回购不安全,但我想知道私人回购是否安全?
我有memoization fibonacci代码,我无法弄清楚时间复杂性是什么:
function fibMemo(index, cache) {
cache = cache || [];
if (cache[index]) return cache[index];
else {
if (index < 3) return 1;
else {
cache[index] = fibMemo(index - 1, cache) + fibMemo(index - 2, cache);
}
}
return cache[index];
}
Run Code Online (Sandbox Code Playgroud)
这个函数的时间复杂度是多少?
我正在试图将可观察的变速器ActivatedRoute转换为承诺,但没有任何运气.我已http成功将请求转换为承诺:
this.riaService.getAdvisorsForState(this.activeState)
.then(rias => {
this.riasForState = rias.json();
console.log(this.riasForState);
});
// this all works ^
Run Code Online (Sandbox Code Playgroud)
但是我无法将'activatedRoute.params'变成一个承诺:
export class InvestmentAdvisorStateComponent implements OnInit {
constructor(private activatedRoute: ActivatedRoute, private riaService: InvestmentAdvisorService) { }
getStateFromUrl() {
this.activatedRoute.params
.toPromise()
.then(params => {
console.log('HERE',params)
});
}
// this does not work for me ^
Run Code Online (Sandbox Code Playgroud)
这就是我现在所拥有的:
getStateFromUrl() {
this.activatedRoute.params
.subscribe((param: any) => {
this.activeState = param['state'];
});
}
// works ^
Run Code Online (Sandbox Code Playgroud)
我希望将此作为一种承诺来实现,所以我可以.then脱离它.任何有关如何做到这一点的帮助非常感谢.
我node8个月前通过自制软件安装了。
我只是尝试通过自制软件升级节点,但没有成功。
相反,我得到一些鼓励我运行一行代码来对其进行修复的消息(我忘记了代码),但我认为它破坏了我的npm,因为我的npm停止工作了,现在我得到了错误:zsh: command not found: npm运行任何npm命令时。
我继续使用本指南完全卸载节点
然后,我开始使用本指南通过自制程序重新安装节点
当我去做冲泡医生时,我发现我坏了很多symlinks,包括很多npm文件,例如:
/usr/local/share/man/man1/npm-README.1
/usr/local/share/man/man1/npm-access.1
/usr/local/share/man/man1/npm-adduser.1
(以及大约60个其他npm文件和其他文件):
/ usr / local / bin / grunt
/ usr / local / bin / gulp
我从这里去哪里?我只是想重新安装node并npm通过自制软件,以便它们正常工作。我应该删除断开的符号链接,brew prune:还是会给我带来更多问题?谢谢。
我有这个功能:
function getTotal () {
var args = Array.prototype.slice.call(arguments);
var total = 0;
for (var i = 0; i < args.length; i++) {
total += args[i];
}
return total;
}
Run Code Online (Sandbox Code Playgroud)
让我们说我有一个充满数字的数组,我不知道它的长度:
var numArray = [ ..., ... ];
Run Code Online (Sandbox Code Playgroud)
如何getTotal通过传入numArray作为参数的每个元素来调用该函数?
我有一个set我在node.js中创建的,我正在尝试Express.js使用res.send或者将它发送到客户端,res.json但是在客户端端集总是显示为空.这是我的代码:
app.get('/test-endpoint', function(req, res) {
let set1 = new Set();
set1.add('SOME ITEM');
console.log('Set 1:', set1); // logs out set1 correctly in the terminal (Set 1 Set: { 'SOME ITEM' })
res.json(set1); // when this gets to the client side it is an empty set ({})
});
Run Code Online (Sandbox Code Playgroud)
为什么会这样?这是Express.js问题吗?