htmlangularjs

AngularJS: How to set default value to ng-model="searchText"?


I am unable to set a default value to ng-model="searchText". Here is the code I am using
<input ng-model="searchText" value="can you see me" />

Can anyone help me with this?


Solution

  • 1st Solution: is to simply init the searchText in the controller.

    App.controller('mainController',['$scope', function($scope) {
       $scope.searchText  = "can you see me";
    }]);
    

    2nd Solution: is to use ng-init instead of value

    <input ng-model="searchText" ng-init="searchText ='can you see me'"></input>