3

I've two codes in my HTML structure.

First one is:

<!DOCTYPE html>
<html lang="en">
<head>
<script src="angular.min.js"></script>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div ng-app>
  <p>Name: <input type="text" ng-model="name"></p>
  <p>{{name}}</p>
</div>
</body>
</html>

and another is:

<!DOCTYPE html>
<html lang="en">
<head>
<script src="angular.min.js"></script>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div ng-app>
  <p>Name: <input type="text" ng-model="name"></p>
  <p ng-bind="name"></p>
</div>
</body>
</html>

Both are giving the same output then, where the difference lies?

TryinHard
  • 4,078
  • 3
  • 28
  • 54
Dibyendu Konar
  • 175
  • 1
  • 1
  • 12

2 Answers2

0

When you are using

<p>{{name}}</p> 

While angularjs is loading, you might see your brackets on the page. You can use ng-cloak to avoid the user to see the {{name}}.

Its better to use

<p ng-bind="name"></p> 

As this removes the problem. the ng-bind will show the value,only when the value is changed. There are so many explanations for the difference you can check

AngularJS : Why ng-bind is better than {{}} in angular?

Difference between ng-bind and interpolation {{}} in Angular

Community
  • 1
  • 1
Hmahwish
  • 2,222
  • 8
  • 26
  • 45
0

The similarity between this two is

  • Used for one way binding.
  • they are used to bind variables on data on view.

Interpolation Directive

This uses {{}} inside that you can have an expression with scope variables which are placed in respective scope..

ng-bind

Sometimes angular shows {{}} while rendering a page which is un-compiled angular content, ng-bind does avoid that. By using this you need use to add using ng-cloak directive.

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299