Azhar Ch Azhar Ch - 4 months ago 7
AngularJS Question

why this AngularJs code is not working as i tried to run some perfect codes too but my browser doesn't run them also

i'm running it using XAMPP but it's not working and showing output of {{"Hello"+"you"}} rather than Hello you

<!DOCTYPE HTML>
<html>
<head ng-app="store">
<link rel="stylesheet" type="text/css" href="bootstrap.min.css"/>
</head>
<body>
<script type="text/javascript" src="angular.min.js">
</script>
<script >
var abc=angular.module('store',[]);
</script>
<p>
{{"Hello"+"you"}}
</p>
</body>
</html>

Answer

First, you should create a controller in your JS, then you use it in your view.

You can do it setting the ng-controller directive, as below:

<!DOCTYPE html>
<html ng-app="store">

<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.7/angular.min.js"></script>
  <script>
    angular.module('store', [])
      .controller('storeCtrl', function($scope) {

      });
  </script>
</head>

<body ng-controller="storeCtrl">
  <p>
    {{"Hello"+"you"}}
  </p>
</body>

Comments