Reputation: 312
I have an input like this
<input type="text" name="name" class="form-control" ng-model="val" ng-change="valx()"/>
Controller:
$scope.val= "start";
$scope.valx = function() {
$scope.val= "done!";
};
However the $scope.val
is not updating in the textbox. I am running on angular v1.2.14
Upvotes: 3
Views: 2760
Reputation: 13943
The code provided is working. The error certainly comes from another part of your code.
ng-app="AppName"
ng-controller="ControllerName"
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.val = "start";
$scope.valx = function() {
$scope.val = "done!";
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<input type="text" name="name" class="form-control" ng-model="val" ng-change="valx()" />
</div>
Upvotes: 2
Reputation: 38683
You can't do it. You need a span to display it. Otherwise the value will be overrated on the same text field.
<input type="text" name="name" class="form-control" ng-model="val" ng-change="valx()"/>
<span>{{result}}</span>
Controller:-
$scope.val="start";
$scope.result= "start";
$scope.valx = function() {
$scope.result= "done!";
};
Upvotes: 0