Search code examples
angularjsangularjs-ng-modelangularjs-ng-value

There is issue $scope value doesn't bind to ng-model at first time load


I want to display some default template in text area at very first loading.I tried to get that output but my code doesn't work.I put all breakpoints that value change.that also doesn't work. When second time data will display on text area.

<textarea meditor style="height: 100%;margin-top: 10px;border: 1px solid lightgray;" ng-model="activity.GoCode" name="gocode" required>{{activity.GoCode}}</textarea>

function getGoCode(data) {
    if (data.GoCode == undefined) {
           $scope.activity.GoCode = "test";
    } else {
          $scope.activity.GoCode = data.GoCode;
          };
    }

Solution

  • I Found solution for this I set a value initially for this variable (activity.GoCode) before that I create '$scope.activity' object and then assign value for when data is loaded.

       $scope.ReadSampleGoFile = function () {
    
            $http.get('settings/sampleGO.txt').then(function (data) {
                //use the file data here
                // console.log(data.data);
                 $scope.activity=[];
                 $scope.activity.GoCode=data.data;
            });
        }