0

I have this fiddle (which won't work, I don't know why. Will be glad if someone would help to fix it). The code in the fiddle is:

HTML:

<body ng-app="testApp">
    <div ng-controller="AppCtrl">
        <span>kid name is {{kids[0].name}}</span><br />
        <input type="text" ng-model="kids[0].name" value={{kids[0].name}} > <br />
        <span>kid age is  {{kids[0].age}}</span> <br />
        <input type="range" value={{kids[0].age}} >

        <div ng-repeat="kid in kids">
            <br />
            The kid's name is <strong id="name">{{kid.name}}</strong> and his age is {{kid.age}}
            <br />
            <input type="range" value={{kid.age}} >
        </div>
    </div>
</body>

JS:

var testApp = angular.module('testApp', []);

testApp.controller('AppCtrl', function ($scope, $http)
{
    $scope.kids = [{"name": "Din", "age": 11}, {"name": "Dina", "age": 17}];
});

The problem is that the range (age) input is not binded to the the span above it ("kid age is {{kid.age}}").

Why there is no binding?

2
  • The correct answer, the one from nubinub, was actually downvoted and deleted! The fact is that Angular does its binding with ng-model NOT with value. Plus the fact that the fiddle was not even working (it needed the "No wrap" option, as pointed out by others). Commented May 9, 2014 at 7:33
  • @vlio20 Take a look at my answer Commented May 9, 2014 at 7:33

2 Answers 2

2

Your fiddle was configured incorrectly. You should select "No wrap in " below the AngularJs version.

Here is the updated fiddle.

In addition to the change in setting, you also need to add ng-model to the range input like @nubinub suggested.

<input type="range" ng-model="kid.age" value="{{kid.age}}">
Sign up to request clarification or add additional context in comments.

2 Comments

why should I add it? for the text input it is working without it.
The value is redundant, only ng-model is needed.
1

Change the onLoad to No Wrap in JSFiddle

Also use ng-model in input field for binding with the angularjs

change

 <input type="range" value={{kid.age}} >

to

Take a look at this

Working Demo

<body ng-app="testApp">
<div ng-controller="AppCtrl">
    <span>kid name is {{kids[0].name}}</span><br />
    <input type="text" ng-model="kids[0].name" value={{kids[0].name}} > <br />
    <span>kid age is  {{kids[0].age}}</span> <br />
    <input type="text" value={{kids[0].age}} >

    <div ng-repeat="kid in kids">
        <br />
        The kid's name is <strong id="name">{{kid.name}}</strong> and his age is {{kid.age}}
        <br />
        <input type="range" ng-model="kid.age" value="{{kid.age}}">
    </div>
</div>

3 Comments

Hi, the fiddle you posted not working (there is still no binding).
also use ng-model in input field for binding with the angularjs
Not really relevant, but this fiddle uses Angular 1.0.2 instead of 1.2.1... don't get why sanitize and resource should be added

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.