2

Typescript

import { Component, OnInit } from '@angular/core';
import {loadCalendar} from '../../../../scripts/artist/artist-home';
import {activate_searchBar} from 
'../../../../scripts/search_bar_activate';
@Component({
 selector: 'app-artist-home',
 templateUrl: './artist-home.component.html',
 styleUrls: ['./artist-home.component.scss']
  })
export class ArtistHomeComponent implements OnInit {

constructor() { }

ngOnInit() {
loadCalendar();
activate_searchBar()
 }

 }

JavaScript

  export function deactivate_searchBar(){

  $('#search_box').attr('disabled','disabled');
  $('#search_button').attr('disabled','disabled')
  }

  export function activate_searchBar(){
  $('#search_box').removeAttr('disabled');
  $('#search_button').removeAttr('disabled')
   }

angular.json

          "scripts": [

          "node_modules/jquery/dist/jquery.js",
          "node_modules/popper.js/dist/umd/popper.js",
          "node_modules/bootstrap-material-design/dist/js/bootstrap- 
           material-design.min.js",
          "node_modules/arrive/src/arrive.js",
          "node_modules/moment/moment.js",
          "node_modules/perfect-scrollbar/dist/perfect-scrollbar.min.js",
          "node_modules/bootstrap-notify/bootstrap-notify.js",
          "node_modules/chartist/dist/chartist.js",
          "node_modules/jquery/dist/jquery.min.js",
          "node_modules/popper.js/dist/umd/popper.min.js",
          "node_modules/bootstrap/dist/js/bootstrap.min.js",
          "src/scripts/side_bar.js",
          "src/scripts/search_bar_activate.js",
          "src/scripts/rating_system.js",
          "src/scripts/image_uploader.js",
          "src/scripts/state_data.js",
          "src/scripts/redirect_to.js",
          "src/scripts/drop_down_nav.js"
        ]

How should i export functions from javascript?

Expect to call the activate_searchBar() function. But the console shows an error

"Uncaught Syntax Error: Unexpected token export"

BLasan
  • 57
  • 4
  • take a look at this... https://stackoverflow.com/questions/54320967/nodejs-how-to-import-js-file-into-typescript – iams0nus Aug 31 '19 at 04:04

1 Answers1

1

You can try like the below, let me know your output

  const deactivate_searchBar = () => {
     $('#search_box').attr('disabled','disabled');
     $('#search_button').attr('disabled','disabled')
     return;
  }

  const activate_searchBar = () => {
     $('#search_box').removeAttr('disabled');
     $('#search_button').removeAttr('disabled');
     return;
  }
  export default {deactivate_searchBar, activate_searchBar}




import objFn from 
'../../../../scripts/search_bar_activate'; //updated

objFn.activate_searchBar() //updated

There are few other function expression,

Source - How can I export all functions from a file in JS?

export var foo = function() {
    // ...
};
export let bar = () => {
    // ...
};
export const baz = value => {
    // ...
};
Kannan G
  • 974
  • 6
  • 9
  • It worked! But other script files in angular.json not working properly – BLasan Aug 31 '19 at 04:12
  • thanks you mean import {loadCalendar} from '../../../../scripts/artist/artist-home';? – Kannan G Aug 31 '19 at 04:13
  • files imported in typescripts work fine. But the scripts included only within angular.json file are not workng. "src/scripts/image_uploader.js" script not working – BLasan Aug 31 '19 at 04:25
  • install and include 'tether.js`in the scripts list it will work - refer - https://stackoverflow.com/questions/52968487/angular-json-scripts-not-loading – Kannan G Aug 31 '19 at 04:28
  • Its not working. I rebuild the project. Then "TypeError: scripts.ymap is not a function" error occurs – BLasan Aug 31 '19 at 04:54