angular.js - angularjs $scope value undefined
怪我咯
怪我咯 2017-05-15 16:50:18
0
3
624
  <form class="ui form" id="indexForm" name="indexForm" onsubmit="return false;">
    <span id="QuacorGradingValue" ng-model="fen" name="fen">6</span>
</form>

Why can’t I get it in the controller

    var updateData = {};
    alert("$scope.rates==="+$scope.fen);//undefined

//$scope is valuable

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(3)
伊谢尔伦
<body ng-controller="controller">
大家讲道理
data-ng-init='fen=6'

controller:

$scope.$watch("fen", function(){
    console.log($scope.fen);
});

http://stackoverflow.com/questions/19981627/setting-scope-property-with-ng-init-doesnt-work

Peter_Zhu

Suppose your controller looks like this:

module.controller('DemoController', ['$scope', function($scope) {
    $scope.fen = '';   //为其指定一个初始值,这样在html里引用时才不会因为parent scope里没有找到`fen`变量而重新创建一个
}]);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template