1

js:

$scope.hello = "hello world";

html:

<input ng-model="hello">
<label>{{hello}}</label>

It sets the label good on initializing but after that it stop updating. What's wrong?

2
  • you did properly as os per your code there were no clues for errors so i just updated my answer Commented Mar 9, 2016 at 15:31
  • So what leaded you to accept the above answer .. can you pls let me know whats wrong with my answer where i can improve ??? Commented Mar 9, 2016 at 15:41

2 Answers 2

1

Try to use this in your controller:

$scope.system = {};
$scope.system.hello = 'hello world';
Sign up to request clarification or add additional context in comments.

Comments

1

Here you Go
as per your code there were no clues for errors so i just answered with working code and some definition of 2-way data-binding The updating is called two-way binding a good feature from angular .

Little Brief about 2 way data binding :-

Two way data binding in angularjs framework is approach to synchronize the data between model and view. What it means that if there is any change happens in model ( Back-end ) then view ( front-end ) will be updated and vice versa.

data binding docs Angular data binding Documentation

Sample Js: -

'use strict';
 var app = angular.module('mainApp', []);
app.controller('registerCtrl', ['$scope', function($scope){
    $scope.hello='hello world';
 }]);

Html :-

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

  <head>
    <link rel="stylesheet" href="style.css">
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
    <script src="script.js"></script>
  </head>

  <body ng-controller="registerCtrl">

    <input type="text" ng-model="hello"/>
    {{hello}}

</body>

</html>

You properly Binded to the text box with model

plunker https://plnkr.co/edit/go9r3x?p=preview

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.