为什么ngOnInit()在Injectable课程解决后没有打电话?
码
import {Injectable, OnInit} from 'angular2/core';
import { RestApiService, RestRequest } from './rest-api.service';
@Injectable()
export class MovieDbService implements OnInit {
constructor(private _movieDbRest: RestApiService){
window.console.log('FROM constructor()');
}
ngOnInit() {
window.console.log('FROM ngOnInit()');
}
}
Run Code Online (Sandbox Code Playgroud)
控制台输出
FROM constructor()
Run Code Online (Sandbox Code Playgroud) 如何列出所有本地安装的NuGet包?是否有NuGet相当于RPM -qa?在巧克力里面,chocolatey list -localonly但是对于我的生活,我找不到NuGet相当于那个命令.
我一直试图将属性值传递给我的组件.从我所读到的一切看起来都是正确的.但它仍然无法正常工作.我的测试值输出到屏幕,控制台为null.:(
这是我的测试组件:
import {Component, Input} from 'angular2/angular2';
@Component({
selector: 'TestCmp',
template: `Test Value : {{test}}`
})
export class TestCmp {
@Input() test: string;
constructor()
{
console.log('This if the value for user-id: ' + this.test);
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我从父页面调用组件的方式.
<TestCmp [test]='Blue32'></TestCmp>
Run Code Online (Sandbox Code Playgroud)
当页面呈现时,测试值为空.我只看到'测试价值:'.
而不是'测试值:Blue32'.
我总是使用类似下面的东西来实现它:
INSERT INTO TheTable
SELECT
@primaryKey,
@value1,
@value2
WHERE
NOT EXISTS
(SELECT
NULL
FROM
TheTable
WHERE
PrimaryKey = @primaryKey)
Run Code Online (Sandbox Code Playgroud)
...但是一旦加载,就会发生主键违规.这是唯一插入此表的语句.那么这是否意味着上述陈述不是原子的?
问题是,这几乎不可能随意重建.
也许我可以将其更改为以下内容:
INSERT INTO TheTable
WITH
(HOLDLOCK,
UPDLOCK,
ROWLOCK)
SELECT
@primaryKey,
@value1,
@value2
WHERE
NOT EXISTS
(SELECT
NULL
FROM
TheTable
WITH
(HOLDLOCK,
UPDLOCK,
ROWLOCK)
WHERE
PrimaryKey = @primaryKey)
Run Code Online (Sandbox Code Playgroud)
虽然,也许我使用错误的锁或使用过多的锁定或其他东西.
我在stackoverflow.com上看到了其他问题,其中答案是建议"IF(SELECT COUNT(*)... INSERT"等),但我总是在(可能是不正确的)假设单个SQL语句是原子的.
有没有人有任何想法?
我正在关注这篇文章- 参考代码在GitHub 上。我已经在本地克隆了存储库。
该项目内部有一个反应应用程序。我正在尝试按照同一篇文章的第 7 步在本地运行它:
docker run -p 8080:80 shakyshane/cra-docker
Run Code Online (Sandbox Code Playgroud)
这将返回:
Unable to find image 'shakyshane/cra-docker:latest' locally
docker: Error response from daemon: pull access denied for shakyshane/cra-docker, repository does not exist or may require 'docker login'.
See 'docker run --help'.
Run Code Online (Sandbox Code Playgroud)
我尝试再次登录docker,但看起来由于它属于@shakyShane,我无法访问它。
我也愚蠢地尝试npm start过,但它不是在节点上运行的简单反应应用程序 - 它在容器中并且容器不受控制npm
看起来像docker pull shakyshane/cra-docker:latest抛出这个:
Error response from daemon: pull access denied for shakyshane/cra-docker, repository does not exist or may …Run Code Online (Sandbox Code Playgroud) 我正试图从Angular 2前端与一个有点RESTful的API交谈.
要从集合中删除某些项目,除了可以附加到URL之外,我还需要发送一些其他数据(即可以附加到URL),即身份验证令牌,某些集合信息和一些辅助数据.
我发现这样做最直接的方法是将身份验证令牌放入请求标头和正文中的其他数据.
但是,Angular 2的Http模块并不完全赞同带有正文的DELETE请求,并尝试发出此请求
let headers= new Headers();
headers.append('access-token', token);
let body= JSON.stringify({
target: targetId,
subset: "fruits",
reason: "rotten"
});
let options= new RequestOptions({headers:headers});
this.http.delete('http://testAPI:3000/stuff', body,options).subscribe((ok)=>{console.log(ok)}); <------line 67
Run Code Online (Sandbox Code Playgroud)
给出了这个错误
app/services/test.service.ts(67,4): error TS2346: Supplied parameters do not match any signature of call target.
Run Code Online (Sandbox Code Playgroud)
现在,我在语法方面做错了吗?我很确定每个RFC都支持DELETE主体
是否有更好的方式来发送数据?
或者我应该将其转储到标题中并将其称为一天?
任何关于这个难题的见解都将受到赞赏
可以使用angular cli生成服务,并在app.module.ts中将其作为提供程序添加到一个步骤中,或者使用ng g service命令中的特殊选项?
执行时:
$ ng g service services/backendApi
installing service
create src/app/services/backend-api.service.spec.ts
create src/app/services/backend-api.service.ts
WARNING Service is generated but not provided, it must be provided to be used
Run Code Online (Sandbox Code Playgroud)
在它旁边,(并根据警告消息)我通常使用文本编辑器将它添加到app.module.ts上的提供程序部分:
@NgModule({
declarations: [
AppComponent,
...
],
imports: [
....
],
providers: [BackendApiService],
bootstrap: [AppComponent]
})
Run Code Online (Sandbox Code Playgroud)
只需一步就可以实现自动化吗?
如何在父组件内创建子组件,然后使用Angular2在视图中显示它们?如何确保将注射剂正确注射到儿童组件中?
import {Component, View, bootstrap} from 'angular2/angular2';
import {ChildComponent} from './ChildComponent';
@Component({
selector: 'parent'
})
@View({
template: `
<div>
<h1>the children:</h1>
<!-- ??? three child views shall be inserted here ??? -->
</div>`,
directives: [ChildComponent]
})
class ParentComponent {
children: ChildComponent[];
constructor() {
// when creating the children, their constructors
// shall still be called with the injectables.
// E.g. constructor(childName:string, additionalInjectable:SomeInjectable)
children.push(new ChildComponent("Child A"));
children.push(new ChildComponent("Child B"));
children.push(new ChildComponent("Child C"));
// How to create the …Run Code Online (Sandbox Code Playgroud) angular ×4
javascript ×4
typescript ×4
android ×1
angular-cli ×1
api ×1
apt-get ×1
asp.net ×1
bots ×1
c# ×1
concurrency ×1
docker ×1
docker-run ×1
http-delete ×1
installation ×1
java ×1
linux ×1
locking ×1
macos ×1
nuget ×1
python ×1
rest ×1
sql ×1
sql-server ×1
t-sql ×1
ubuntu ×1
whatsapp ×1