1- install this library 
npm i -D html-loader
============================================================
2- In webpack.config   use html-loader for html files
 { test: /\.html$/,  loaders: ['html-loader']   }
============================================================
3- If you use ionic , you can copy webpack.config.js  from the path 
"node_modules/@ionic/app-scripts/config/webpack.config.js"
then add the html loader to it
=============================================================
4-If you use ionic
In package.json add these lines
"config": { 
    "ionic_bundler": "webpack",
    "ionic_webpack": "webpack.config.ionic.js" 
  },
=============================================================
5-Then you can use it as below 
@Component({
  selector: 'page-login',
 // templateUrl:"./login.html"
   template:     function(){
    if(globalVariables.test==2) {
      return require("./login2.html")
    }
    else
    {
      return require("./login.html")
    }
  }(),
})
======================================
6-If there is unresolved error  with require function you can put it in  declarations.d.ts file as the below :
declare var require: any;