2
 class ServiceRecordGridFields{
  constructor(){
    this.allColumns = [
    {
      field:'assemblynumber',
      name:'Assembly',
      visible:false,
      width:175
    },{
      field:'assetid',
      name:'Asset ID',
      visible:false,
      width:110
    }];
  }
  getAllColumns(){

    return this.allColumns;
  }
}
export default ServiceRecordGridFields;

Elsewhere I have

import ServiceRecordGridFields from './_serviceRecordGridFields.js';


class serviceRecordGridsCtrl{

  constructor(){

this._ServiceRecordGridFields = ServiceRecordGridFields;

this._serviceRecordsResolve = serviceRecordsResolve;


  } 

  bclick(){
console.log(this._ServiceRecordGridFields.getAllColumns());
  }
  }

calling the function I get "this._ServiceRecordGridFields.getAllColumns is not a function".

if I add "static" in front of getAllColumns() it returns undefined. What am I doing wrong?

1
  • You should instantiate ServceRecordGridFields with new, then call getAllColumns on that instance. Commented Oct 26, 2016 at 17:20

2 Answers 2

5

ServiceRecordGridFields is a class so you need to instantiate an object using this class:

this._ServiceRecordGridFields = new ServiceRecordGridFields()
Sign up to request clarification or add additional context in comments.

Comments

2
class ServiceRecordGridFields {
   constructor() {
     this.allColumns = [{
       field: 'assemblynumber',
       name: 'Assembly',
       visible: false,
       width: 175
     }, {
       field: 'assetid',
       name: 'Asset ID',
       visible: false,
       width: 110
     }];
   }
   getAllColumns() {

     return this.allColumns;
   }
 }

 class serviceRecordGridsCtrl {

   constructor() {

     this._ServiceRecordGridFields = new ServiceRecordGridFields();



   }

   bclick() {
     console.log(this._ServiceRecordGridFields.getAllColumns());
   }
 }

 var test = new serviceRecordGridsCtrl();
 test.bclick();

You need to instantiate both classes to use them.

https://jsfiddle.net/68pep88x/1/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.