javascriptangularjsng-init

get ng-init value from scope


I want to get ng-init value from angular scope

controller

$scope.data={}
$scope.initvalue="myvalue";

Html

<input type="text" ng-model="data.value" ng-init="data.value= initvalue">

I want to set initvalue in input box and sent it to controller by ng-model(I want to able to modify this values so I need to make that)


Solution

  • Does this make sense?

    http://jsfiddle.net/c7bsrenu/2/

    var myApp = angular.module('myApp',[]);
    
    function MyCtrl($scope) {
      $scope.data={}
      $scope.initvalue="myvalue";
      $scope.$watch('data.value', function(newVal, oldVal) {
          console.log(newVal);
          console.log(oldVal);
      });
    }