Aniket Aniket - 2 months ago 13
AngularJS Question

Angular JS Templating

i have a template set for all my view pages which i load using

app.route('/*').get(core.renderIndex);


where and the renderIndex function looks like

exports.renderIndex = function (req, res) {
res.render('modules/core/server/views/index', {
user: req.user || null
});
};


Now when my route has announcement in it i render a different template and not index.server.view.html

app.route('/:shopId/:locationId/announcement/*').get(core.renderAnnouncement);

exports.renderAnnouncement = function (req, res) {
res.render('modules/core/server/views/announcement', {
user: req.user || null,
});
};


The reason why i'am doing this is because i need to change the meta tags over this page i.e. i need to set variables on view before the page renders which comes from another controller.

My question is how can i access variables in a server.view.html file?

<!DOCTYPE html>
<html lang="en" ng-controller="OfferController" ng-init="getAnnouncement()">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
<base href="/">
<title>{{ gettitle }}</title>


like the gettitle which is setting from getAnnouncement method of OfferController.

This works if i set a different announcement.client.view.html file and in the server file extend it

Answer

In case someone is stuck and needs help here is how i did this

 app.get('/:shopId/:locationId/announcement/*',function(req,res,next){
    async.waterfall([
      function (done) {
        var resultsObj = '';  
        var httpTransport = 'http://';
        if (config.secure && config.secure.ssl === true) {
          httpTransport = 'https://';
        } 
        var url = httpTransport + req.headers.host+'/api/offer/getbyid/'+req.params[0];
        request.get(url, function (err, res, body) {
          resultsObj = JSON.parse(body);
          done(err, resultsObj);
        });


      },
      function (resultsObj, done) {
        var httpTransport = 'http://';

        if (config.secure && config.secure.ssl === true) {
          httpTransport = 'https://';
        } 
        var url = httpTransport + req.headers.host+'/api/shops/'+req.params.shopId+'/'+req.params.locationId;   
        request.get(url, function (err, res, body) {
          var resultsObjNew='';     
          resultsObjNew = JSON.parse(body);
          done(err, resultsObjNew,resultsObj);
        });

      },
      function (resultsObjNew,resultsObj, done) {

        res.render('modules/core/server/views/announcement', {
          title: resultsObj[0].title,
          imageUrl  : resultsObj[0].imageURL,
          desc : resultsObj[0].desc,
          link:resultsObj[0].redirectLink,
          logoLink: resultsObjNew.logoLink,   
          backgroundImage:resultsObjNew.backgroundImage    
        });   
      }    
    ]);
  });

where

  var request = require('request'); 
  var async = require('async'); 
  var path = require('path');