Skip to main content
se añadieron 436 caracteres en el cuerpo
Origen Enlace
NaCl
  • 6.8k
  • 4
  • 30
  • 51
import { Component, OnInit } from '@angular/core';
import { MSOService } from '../../services/mso.services';
import { Subject } from 'rxjs/Subject';
import { ActivatedRoute, Router } from '@angular/router';

@Component({
  selector: 'app-objetos',
  templateUrl: './objetos.component.html',
  styleUrls: []
})
export class ObjetosComponent implements OnInit {

    objetos:any [] = [];
    titles:any [] = [];
    url_activo:object ;
    dtOptions: any = {};
    dtTrigger: Subject<any> = new Subject();

    constructor(public activatedRoute: ActivatedRoute,
                public _msoService: MSOService,
          public router: Router) {
         public router: Router) {
            this.activatedRoute.params
              .subscribe( params => {
                this.url_activo = params;
            });    this.url_activo = params;
             
    }

    ngOnInit(): void {
        this.dtOptions = });{
             pagingType: 'full_numbers',
           }

  ngOnInit()pageLength: void{
10,
this.dtOptions = {

  pagingType: 'full_numbers',
  pageLength: 10,
    dom: 'Bfrtip',
            scrollx: true,
            scrolly: true,
            buttons: [
    
             {
                    extend: 'colvis',
                    collectionLayout: 'fixed two-column',
                    postfixButtons: [ 'colvisRestore' ]
                },
                'copy',
                'print',
                'excel',
                'csv',
                'pdf',
                {
                    text: 'Add ',
                    key: '1',
                    action: function (e, dt, node, config) {
            this.router.navigate(['nuevo']);            //aqui es donde esta el error, this router no definida.
                        this.router.navigate(['nuevo']);
                    }
                }
            ],

            columnDefs: [
                {
                    targets: [0,1],
                    visible: false
                }
            ]
 
        };

        this.activatedRoute.params
            .subscribe( params => {
                this._msoService.getObjetos( params['APPNAME'], params['MODELNAME'])
                    .subscribe(objetos => {
                        this.objetos = objetos;
                        this.titles = Object.keys(objetos[0]);
                        this.dtTrigger.next(objetos);
                    });
 
            });
        }
    }

}

}

import { Component, OnInit } from '@angular/core';
import { MSOService } from '../../services/mso.services';
import { Subject } from 'rxjs/Subject';
import { ActivatedRoute, Router } from '@angular/router';

@Component({
  selector: 'app-objetos',
  templateUrl: './objetos.component.html',
  styleUrls: []
})
export class ObjetosComponent implements OnInit {

objetos:any [] = [];
titles:any [] = [];
url_activo:object ;
dtOptions: any = {};
dtTrigger: Subject<any> = new Subject();

constructor(public activatedRoute: ActivatedRoute,
          public _msoService: MSOService,
          public router: Router) {
            
            this.activatedRoute.params
              .subscribe( params =>{
                
                this.url_activo = params;
                
              });
              
           }

  ngOnInit(): void{

this.dtOptions = {

  pagingType: 'full_numbers',
  pageLength: 10,
  dom: 'Bfrtip',
  scrollx: true,
  scrolly: true,
  buttons: [
    
     {
        extend: 'colvis',
        collectionLayout: 'fixed two-column',
        postfixButtons: [ 'colvisRestore' ]
    },
    'copy',
    'print',
    'excel',
    'csv',
    'pdf',
    {
      text: 'Add ',
      key: '1',
      action: function (e, dt, node, config) {
            this.router.navigate(['nuevo']);//aqui es donde esta el error, this router no definida.

      }
    }
  ],

  columnDefs: [
        {
            targets: [0,1],
            visible: false
        }
    ]
 
};

this.activatedRoute.params
  .subscribe( params =>{
    this._msoService.getObjetos( params['APPNAME'], params['MODELNAME'])
        .subscribe(objetos => {
          this.objetos = objetos;
          this.titles = Object.keys(objetos[0]);
          this.dtTrigger.next(objetos);
        });
 
});

}

}

import { Component, OnInit } from '@angular/core';
import { MSOService } from '../../services/mso.services';
import { Subject } from 'rxjs/Subject';
import { ActivatedRoute, Router } from '@angular/router';

@Component({
  selector: 'app-objetos',
  templateUrl: './objetos.component.html',
  styleUrls: []
})
export class ObjetosComponent implements OnInit {

    objetos:any [] = [];
    titles:any [] = [];
    url_activo:object ;
    dtOptions: any = {};
    dtTrigger: Subject<any> = new Subject();

    constructor(public activatedRoute: ActivatedRoute,
                public _msoService: MSOService,
                public router: Router) {
        this.activatedRoute.params
            .subscribe( params => {
                this.url_activo = params;
            });                   
    }

    ngOnInit(): void {
        this.dtOptions = {
            pagingType: 'full_numbers',
            pageLength: 10,
            dom: 'Bfrtip',
            scrollx: true,
            scrolly: true,
            buttons: [
                {
                    extend: 'colvis',
                    collectionLayout: 'fixed two-column',
                    postfixButtons: [ 'colvisRestore' ]
                },
                'copy',
                'print',
                'excel',
                'csv',
                'pdf',
                {
                    text: 'Add ',
                    key: '1',
                    action: function (e, dt, node, config) {
                        //aqui es donde esta el error, this router no definida.
                        this.router.navigate(['nuevo']);
                    }
                }
            ],

            columnDefs: [
                {
                    targets: [0,1],
                    visible: false
                }
            ]
        };

        this.activatedRoute.params
            .subscribe( params => {
                this._msoService.getObjetos( params['APPNAME'], params['MODELNAME'])
                    .subscribe(objetos => {
                        this.objetos = objetos;
                        this.titles = Object.keys(objetos[0]);
                        this.dtTrigger.next(objetos);
                    });
            });
        }
    }
Origen Enlace

Variable This.router indefinica dentro de una funcion

Estoy trabajando Angular con TypeScript. inserte una tabla con DataTables y en la configuracion de botones tengo un error indefined, me pueden apoyar a decirme como utilizar el objeto This dentro de una funcion. Muestro mi codigo de ejemplo:

import { Component, OnInit } from '@angular/core';
import { MSOService } from '../../services/mso.services';
import { Subject } from 'rxjs/Subject';
import { ActivatedRoute, Router } from '@angular/router';

@Component({
  selector: 'app-objetos',
  templateUrl: './objetos.component.html',
  styleUrls: []
})
export class ObjetosComponent implements OnInit {

objetos:any [] = [];
titles:any [] = [];
url_activo:object ;
dtOptions: any = {};
dtTrigger: Subject<any> = new Subject();

constructor(public activatedRoute: ActivatedRoute,
          public _msoService: MSOService,
          public router: Router) {
            
            this.activatedRoute.params
              .subscribe( params =>{
                
                this.url_activo = params;
                
              });
              
           }

  ngOnInit(): void{

this.dtOptions = {

  pagingType: 'full_numbers',
  pageLength: 10,
  dom: 'Bfrtip',
  scrollx: true,
  scrolly: true,
  buttons: [
    
    {
        extend: 'colvis',
        collectionLayout: 'fixed two-column',
        postfixButtons: [ 'colvisRestore' ]
    },
    'copy',
    'print',
    'excel',
    'csv',
    'pdf',
    {
      text: 'Add ',
      key: '1',
      action: function (e, dt, node, config) {
            this.router.navigate(['nuevo']);//aqui es donde esta el error, this router no definida.

      }
    }
  ],

  columnDefs: [
        {
            targets: [0,1],
            visible: false
        }
    ]

};

this.activatedRoute.params
  .subscribe( params =>{
    this._msoService.getObjetos( params['APPNAME'], params['MODELNAME'])
        .subscribe(objetos => {
          this.objetos = objetos;
          this.titles = Object.keys(objetos[0]);
          this.dtTrigger.next(objetos);
        });

});

}

}