Search code examples
angularjsnode.jsejsangular-ngmodel

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>
  <html>
  <head>

      <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>

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

  </head>

  <body>
        <input ng-model="name"> Hello <%= name %>
  </body>
  </html>

How to get name resolved in ejs template?


Solution

  • 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">
      {{name}}
    </div>

    Perhaps you're just missing your ng-app?