Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 对象文字只能指定已知属性,并且“设置”类型中不存在“选择”_Javascript_Angular - Fatal编程技术网

Javascript 对象文字只能指定已知属性,并且“设置”类型中不存在“选择”

Javascript 对象文字只能指定已知属性,并且“设置”类型中不存在“选择”,javascript,angular,Javascript,Angular,当我尝试用angular编写此javascript代码时,我遗漏了什么 ngOnInit() { $('#jithesh').DataTable( { columnDefs: [ { orderable: false, className: 'select-checkbox', targets: 0 } ], select: { style: 'os', selector:

当我尝试用angular编写此javascript代码时,我遗漏了什么

 ngOnInit() {


  $('#jithesh').DataTable( {
    columnDefs: [ {
        orderable: false,
        className: 'select-checkbox',
        targets:   0
    } ],
    select: {
        style:    'os',
        selector: 'td:first-child'
    },
    order: [[ 1, 'asc' ]]
} );
这是原始的java脚本

$(document).ready(function() {
    $('#example').DataTable( {
        columnDefs: [ {
            orderable: false,
            className: 'select-checkbox',
            targets:   0
        } ],
        select: {
            style:    'os',
            selector: 'td:first-child'
        },
        order: [[ 1, 'asc' ]]
    } );
} );
尝试遵循本示例中的内容

尽可能避免使用Angular的jQuery

在ngOnInit中运行jQuery时,元素不在DOM中。相反,将代码从ngOnInit移动到ngAfterViewInit

演示:

此演示向您展示了在组件的初始生命周期钩子期间document.getElementById'id'.outerHTML的结果:

ngOnInit-未定义 ngAfterContentInit-未定义 ngAfterViewInit-outerHTML 使用的代码:

恩戈尼特{ this.onInit=this.getOuterHtml; } ngAfterContentInit{ this.afterContentInit=this.getOuterHtml; } ngAfterViewInit{ 设置超时=>{ this.afterViewInit=this.getOuterHtml; } } 私有getOuterHtml{ const el=document.getElementById'el'; 返回el?el.outerHTML:“未定义”; }
Docs:

或者更好的做法是,将jquery代码移动到包装该代码的指令中functionality@HarijsDeksnis婴儿步!在这种情况下,我认为自定义指令对于答案来说是一个太远的跳跃。我在角度上很幼稚,仍然在src/app/all-in-one/all-in-one.component.ts53,7:error TS2345:类型为{columnDefs:{orderable:false;className:string;targets:number;}[]的参数中得到这个错误;select:{style:string;selector:string;};顺序:字符串| number[][];}不可分配给“Settings”类型的参数。Object literal只能指定已知属性,并且“设置”类型中不存在“选择”。@JitheshChandra听起来与原始问题无关。你能在我的stackblitz中重复我的实验吗,但是使用$'jithesh'。