Karen Santana
Karen Santana

Reputation: 39

HTML not showing Angularjs's variable value

Im trying to show an Angularjs's variable value in HTML with the following code:

<div ng-controller="MyTextbox">

<p>Fecha de ultima actualizacion: {{nodeID1}} </p>

Here is the code for my angularjs controller:

angular.module("umbraco").controller("MyTextbox", function ($scope,$routeParams) {

$scope.nodeID1 = "Hello World";

});

But nothing display this way. Any help?

Upvotes: 1

Views: 2397

Answers (2)

Luis Menjivar
Luis Menjivar

Reputation: 777

Try:

<!DOCTYPE>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script>

   angular.module("umbraco",[]).controller("MyTextbox", ['$scope', function ($scope, $routeParams) {
    $scope.nodeID1 = "Hello World";
   }]); 

 </script>

</head>
<body >
    <h1>My Textbook</h1>
    <div ng-app="umbraco" ng-controller="MyTextbox">
      <p>Fecha de ultima actualizacion: {{nodeID1}}</p>
    </div>
</body>
</html>

Upvotes: 0

Pankaj Parkar
Pankaj Parkar

Reputation: 136144

You need to write ng-app="umbraco"before ng-controller directive, or write it on body/html tag would be preferable.

Markup

<div ng-app="umbraco" ng-controller="MyTextbox">

    <p>Fecha de ultima actualizacion: {{nodeID1}} </p>

</div>

and your app should be

angular.module("umbraco",[]).controller("MyTextbox", function ($scope,$routeParams) {

     $scope.nodeID1 = "Hello World";
});

Note

If $routeParams has not added mistakenly then your app would be angular.module("umbraco",['ngRoute']) then you need to additionally add angular-route.js

Upvotes: 1

Related Questions