1

Recently I came across a code chunck where JST is added before the template in angular -

Example -

$routeProvider .when("/login", { template: JST["app/templates/login"], controller: "LoginController" })

Previously, I do like this -

$routeProvider .when("/login", { template: "app/templates/login", controller: "LoginController" })

what is this JST in angular template means? also the difference between the two styles if any?

FYI - Its a code in app made from linemanjs.

Trialcoder
  • 5,816
  • 9
  • 44
  • 66

3 Answers3

4

It possibly could be an hash object in your code containing all keys and values as template urls for html files.

var JST = {
    "app/templates/login":"something.html"
};

$routeProvider
    .when("/login", {
        template: JST["app/templates/login"],
        controller: "LoginController"
    })
Raghavendra
  • 5,281
  • 4
  • 36
  • 51
  • I made a folder search with `JST` but no results, I think I am using `linemanjs` (installed globally `-g`) so it must be there if not available locally and not explicitly an angular feature – Trialcoder Jul 16 '14 at 06:38
  • Yes, it must be somewhere else. Its definitely not an angular feature – Raghavendra Jul 16 '14 at 06:41
2

Here's how I use JST templates in Angular:

app.factory('$jst', ['$sce', function($sce) {
  var methods = {
    template: function(name) { return $sce.trustAsHtml( eval(JST[name])() ) }
  };
  return methods;
}]);

app.controller('SomeCtrl', ['$scope', '$http', '$jst', function($scope, $http, $jst) {
  $scope.template = $jst.template('name-of-my-template');
}]);

...and here's my HTML:

<div ng-controller="SomeCtrl">
  <div ng-bind-html="template"></div>
</div>

It's a simple and elegant way to use JST templates from inside AngularJS.

PS It works well with SailsJS too.

Kevin Hutchinson
  • 2,353
  • 2
  • 17
  • 10
1

Your application is using JST templates, this page describes them. JST is a hash that returns the template as a JavaScript function. Often this JST object (hash of functions) is created at build time and saved as a JavaScript file that is included somehow by the app. The input to the compiled JST object is a list of template .html files.

Tom Dunn
  • 2,425
  • 2
  • 13
  • 9
  • Yes. See https://code.google.com/p/trimpath/wiki/JavaScriptTemplates and http://stackoverflow.com/questions/22080981/loading-ng-include-partials-from-local-pre-loaded-jst-template-cache for more info on this. – Kevin Hutchinson Aug 24 '15 at 00:18