Question

I have problem with set text into text input in onsen. How to set text or value for text input in onsen with javascript?

Sorry for my poor english.

Was it helpful?

Solution

In AngularjS, the value chagnes according to the ng-model.
For example, html is

<div ng-controller="MyCtrl" ng-init="text = 'Hello'">
    <ons-text-input 
        ng-model="text"
        style="display: block; width: 100%" value="OK">
    </ons-text-input>

    <div ng-click="setText('changed1');">Change 1!</div>
    <div ng-click="setText('changed2');">Change 2!</div>
    <div ng-click="setText('changed3');">Change 3!</div>
</div>

and js code is

app = angular.module('myApp', ['onsen.directives']);

app.controller('MyCtrl', function($scope) {  
    $scope.setText = function(str) {
       $scope.text = str;
    };    
});

When the variable text which is ng-model itself changes, the value of input changes automatically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top