0

How to pass query string parameter for component in angular

app.component('test', {
     templateUrl: '/_directive/test.tpl.html',
     bindings: {
     currenttab: "="
     },
     controllerAs: 'test',
     controller: test  });

I want to like this:

 templateUrl: '/_directive/test.tpl.html?version=' + version;

1 Answers1

0

You can't use the url as "/_directive/test.tpl.html" + version, becuse that will compile to /_directive/test.tpl.html0.0.1 and this html is not found, so we should change it to "/_directive/test.tpl.html?" + version or "/_directive/test.tpl.html?version=" + version to have better result:

/_directive/test.tpl.html?0.0.1
/_directive/test.tpl.html?version=0.0.1

for sending public params in all the project we have to set theme before define angular app, see the example

window.version = "0.0.1";

var app = angular.module("app", ["ngRoute"]);

app.component('test', {
    templateUrl: 'partials/home-template.html?' + window.version,
    controller: function() {
        console.log(window.version)
    }
});

check your Network tab in the chrome or firefox to see the compile mode.

Maher
  • 2,517
  • 1
  • 19
  • 32
  • Your answer is right, but **templateUrl** not access direct value. So i have use **template** field and use ng-transclude & fire on change event on controller – Kaushik Dhameliya Jun 18 '17 at 15:49
  • Right answer : https://stackoverflow.com/questions/33841909/angular-1-5-component-method-templateurl-function?noredirect=1&lq=1 – Kaushik Dhameliya Jun 18 '17 at 15:51