How to set scope property with ng-init?

前端 未结 6 458
借酒劲吻你
借酒劲吻你 2020-11-30 02:26

I am trying to set the value of a $scope property using ng-init, and I am unable to access that value in the controller\'s javascript. What am I doing wrong? Here is a fidd

6条回答
  •  半阙折子戏
    2020-11-30 03:00

    Just set ng-init as a function. You should not have to use watch.

    
      
    {{ testInput }}
    app.controller('MainCtrl', ['$scope', function ($scope) { $scope.testInput = null; $scope.init = function(value) { $scope.testInput= value; } }]);

    Here's an example.

    Plunker

提交回复
热议问题