Rohit Rohit - 1 year ago 86
AngularJS Question

Angular JS not rendering HTML

I am new to Angular JS. I wrote a simple Angular code but the HTML is not rendering correctly or the expression is not getting evaluated. Please help with what i am missing. I am using angular.min.js minified(1.6).

<!DOCTYPE html>
<html ng-app>
<script src="js/angular.min.js"></script>
function MyFirstCtrl($scope) {
var employees = ['Catherine Grant', 'Monica Grant',
'Christopher Grant', 'Jennifer Grant'];

$scope.ourEmployees = employees;
<body ng-controller='MyFirstCtrl'>
<h2>Number of Employees: {{ ourEmployees.length}}</h2>

Answer Source

Set a root for your application with the ng-app directive and create a controller for your app from which you can handle the $scope:

var app = angular.module("ng-app", []);
app.controller("myCtrl", function($scope) {
  var employees = ['Catherine Grant', 'Monica Grant', 'Christopher Grant', 'Jennifer Grant'];
  $scope.ourEmployees = employees;

<!DOCTYPE html>
<script src=""></script>
<div ng-app="ng-app">
<div ng-controller="myCtrl">
  <h2>Number of Employees: {{ ourEmployees.length}}</h2>

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