2

how to set a value for an input form in angularjs?

this is my input form:

<input type="text" placeholder="John" ng-model="dataOrang.nama">
2
  • What ever you type will gets stored in $scope.dataOrang.nama Commented Sep 7, 2016 at 6:17
  • thanks, thats work Commented Sep 7, 2016 at 6:37

3 Answers 3

3

You can set value in controller like below.

$scope.dataOrang = {
        nama : "SomeValue"
    }

Ref: http://jsfiddle.net/Lvc0u55v/9233/

Sign up to request clarification or add additional context in comments.

Comments

2

Add these in an controller, $scope.dataOrang.nama = "Sample Data"

Comments

0

ng-value = Specifies the value of an input element.
ng-model = Binds the value of HTML controls to application data.

var app = angular.module( "myApp", [] );

app.controller( "myCtrl", ["$scope", function($scope) {

    // set value from app to input html
    $scope.value = {
        nama: "Doe"
    };

}] );
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>

<div ng-app="myApp" ng-controller="myCtrl">

    <input type="text" placeholder="John" ng-model="model.nama" ng-value="value.nama" />     

    <!-- get value from input html into p tag -->
    <p>Nama: {{ model.nama }}</p>

</div>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.