dreamer dreamer - 5 months ago 31
Node.js Question

How to resolve a ng-model variable from angularJS in ejs template

I am using MEAN stack.

I have set my templating engine as 'ejs',
and now when i try to attach an ng-model, it is not getting resolved in the ejs template.

Things tried till now:

  • tried using html template(and then used '{{' '}}'), but did not work

  • in ejs template used '<%=' '%>', with no result

Code for index.ejs is given below

<!DOCTYPE html>

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>

<link rel="stylesheet" href="/stylesheets/style.css">


<input ng-model="name"> Hello <%= name %>

How to get name resolved in ejs template?

Answer Source

No reason to use ejs along with angular really. Let angular handle the templating and binding data in the view, setup your server side components (express, mongo, and node) to act as an API that uses JSON objects to communicate the request and response body.

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<div ng-app="">
  <input type="text" ng-model="name">

Perhaps you're just missing your ng-app?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download