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">
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">
You can set value in controller like below.
$scope.dataOrang = {
nama : "SomeValue"
}
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>