Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular 2 how to import custom function to component and service

I have a function like this

myHelperNumber.js

function myLittleBoy(){
  console.log('I see you)
}

How to use this function in User.js component or userSevicer.js service?

like image 713
angry kiwi Avatar asked Jan 03 '17 07:01

angry kiwi


2 Answers

myHelperFunction.ts

export function myLittleBoy(){
  console.log('Hello World')
}

RegisterComponent.ts

import {myLittleBoy} from 'path to myhelperfunction.ts'
like image 177
angry kiwi Avatar answered Sep 28 '22 04:09

angry kiwi


export function myLittleBoy(){
  console.log('I see you)
}



import { Component } from '@angular/core';
declare var myLittleBoy:any;
@Component({
  selector: 'my-app',
  template: '<h1>Hello {{name}}</h1>',
})
export class AppComponent  { 

    constructor(private __jsmodel:JSmodelEvents){
        myLittleBoy();

    }

}
like image 40
anshuVersatile Avatar answered Sep 28 '22 03:09

anshuVersatile