我从扩展文件导入声明时遇到问题(我正在使用此类型).根据示例,我应该将其放入我的代码中:
import * as SockJS from 'sockjs-client';
import BaseEvent = __SockJSClient.BaseEvent;
import SockJSClass = __SockJSClient.SockJSClass;
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试按以下方式执行此操作时:
module Test {
import * as SockJS from 'sockjs-client';
import BaseEvent = __SockJSClient.BaseEvent;
import SockJSClass = __SockJSClient.SockJSClass;
export class Example {
constructor() {......
}}}
Run Code Online (Sandbox Code Playgroud)
我从编译器得到以下错误:
error TS1147: Import declarations in a namespace cannot reference a module.
Run Code Online (Sandbox Code Playgroud)
难道我做错了什么?或者打字本身有什么问题吗?
谢谢
uksz
我的功能有问题:
copyObject<T> (object:T):T {
var objectCopy = <T>{};
for (var key in object) {
if (object.hasOwnProperty(key)) {
objectCopy[key] = object[key];
}
}
return objectCopy;
}
Run Code Online (Sandbox Code Playgroud)
我有以下错误:
Index signature of object type implicitly has an 'any' type.
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
我一直在挖掘,发现我可以使用以下内容在对象上使用*ngFor:
<div *ngFor="#obj of objs | ObjNgFor">...</div>
Run Code Online (Sandbox Code Playgroud)
其中ObjNgFor管道是:
@Pipe({ name: 'ObjNgFor', pure: false })
export class ObjNgFor implements PipeTransform {
transform(value: any, args: any[] = null): any {
return Object.keys(value).map(key => value[key]);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我有这样的对象时:
{
"propertyA":{
"description":"this is the propertyA",
"default":"sth"
},
"propertyB":{
"description":"this is the propertyB",
"default":"sth"
}
}
Run Code Online (Sandbox Code Playgroud)
我不太确定如何提取'propertyA'和'propertyB',以便可以从*ngFor指令访问它.有任何想法吗?
UPDATE
我想要做的是呈现以下HTML:
<div *ngFor="#obj of objs | ObjNgFor" class="parameters-container">
<div class="parameter-desc">
{{SOMETHING}}:{{obj.description}}
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
什么东西等于propertyA和propertyB(这是对象的结构).所以,这会导致:
propertyA:this is the propertyA
propertyB:this is the …Run Code Online (Sandbox Code Playgroud) 所以我遇到了网络,我想知道void在Typescript 中意味着什么?
就像这里一样:
private _handleProjectQuerySuccess(data: IProject[]): void
{
data.sort(this._projectSort);
var pathname = this._$location.path();
var activeSet = false;
data.forEach((project: IProject) =>
{
project.active = pathname == '/' + project.id;
activeSet = activeSet || project.active;
project.name = this._$sanitize(project.name);
project.description = this._$sanitize(project.description);
project.url = this._$sce.trustAsUrl(project.url);
project.readme = this._$sce.trustAsHtml(project.readme);
project.title = project.name + (project.fork ? ' (fork)' : ' (repo)');
this._scope.projects.push(project);
this._projectMap[project.id] = this._scope.projects[this._scope.projects.length - 1];
});
if (!activeSet)
{
data[0].active = true;
}
}
Run Code Online (Sandbox Code Playgroud)
在我们宣布私有之后,我们暗示void......这是什么意思?
我想知道我怎么能以不同的方式进入同一个州$stateParam呢?
我试着去:
$state.go('^.currentState({param: 0})')
Run Code Online (Sandbox Code Playgroud)
但是,它无法正常工作.
我遇到了问题ngOnChange.我有以下组件:
@Component({
selector:'user-table',
template: `...`,
})
export class UserTable implements OnChanges{
@Input() users: User[];
years:string[];
constructor(private _usersCollection:UsersCollection){
}
ngOnChanges(){
if (this.users.length)
{this.years =this._usersCollection.createYearsArray(this.users)}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果条件仅被检查一次 - 何时this.users尚未从服务器获取,因此其长度为0.我如何找到处理这种异步输入的解决方案?
更新数组,就像我设置以下日志时一样:
console.log('ON FIRST INIT' , this.programs);
this.years = this._usersCollection.createYearsArray();
console.log(this.years);
setInterval(()=>{
console.log('IN INTERVVAL' , this.programs);
},1000);
Run Code Online (Sandbox Code Playgroud)
控制台输出是:
ON FIRST INIT []
UsersTable.component.ts:21 []
UsersTable.component.ts:23 IN INTERVVAL [Object, Object, Object, Object]
Run Code Online (Sandbox Code Playgroud) 我想知道如何将以下形式的Validator设置为Required,仅当表单元素存在时:
<div *ngIf="form.controls.user.value !== 'Admin' && form.controls.user.value ">
<label>Role:</label>
<input type="text" ngControl="role">
</div>
Run Code Online (Sandbox Code Playgroud)
我的表格是:
this.form = this._formBuilder.group({
user: ['',Validators.required],
role: ['', Validators.required]
});
Run Code Online (Sandbox Code Playgroud) 我想知道如果我在我的构造函数中订阅流如下:
_eventEmitterService.event.subscribe((msg)=>{})
Run Code Online (Sandbox Code Playgroud)
因此,当我将视图更改为不同的组件并返回时,事件将从该流触发两次.每次更改组件时,是否需要取消订阅ngOnDestroy?
谢谢
我想知道是否可以订阅更改对象,即数组.我的用例如下:用户重新加载页面,需要加载整个集合,然后获取一个具有特定id的对象.据我所知,我可以创建一个这样的函数:
在构造函数中:
this.getById(id);
Run Code Online (Sandbox Code Playgroud)
而且功能
getById(id: string){
this.object = this.objectsService.getById(id);
if (this.object.name){ //check if object exist
//Do something
} else {
setTimeout(()=>{
this.getById(id)
}, 1000);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我觉得这不是最好的事情.那么,我想做的是这样的事情:
let objects = this.objectService.getObjects() // returns object that will hold the collection;
objects.subscribe((value) => {
if(value.length) {
//Do something
}
});
Run Code Online (Sandbox Code Playgroud) 我的插件有问题.当我在应用程序中,并且我通过Parse发送通知时,我会收到一条带有该消息的警报(这可以按预期工作).但是,当应用程序在后台时,手机上不会显示任何内容.以下是我如何使用插件,以及如何处理通知:
var gmcId = "xxxxxxx";
var androidConfig = {
senderID: gmcId
};
document.addEventListener("deviceready", function(){
$cordovaPush.register(androidConfig).then(function(result) {
console.log("result: " + result);
}, function(err) {
// Error
})
$rootScope.$on('$cordovaPush:notificationReceived', function(event, e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
// Your GCM push server needs to know the regID before it can push to this device
// here is where you might want to send it the regID for later use.
console.log("regID = " + e.regid); …Run Code Online (Sandbox Code Playgroud) typescript ×6
angular ×5
android ×1
angularjs ×1
ionic ×1
javascript ×1
ngfor ×1
object ×1
rxjs ×1
state ×1