扫码关注官方订阅号
6
在controller里面为啥获取不到
var updateData = {}; alert("$scope.rates==="+$scope.fen);//undefined
//$scope是有值的
走同样的路,发现不同的人生
<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
假设你的controller是这样的:
controller
module.controller('DemoController', ['$scope', function($scope) { $scope.fen = ''; //为其指定一个初始值,这样在html里引用时才不会因为parent scope里没有找到`fen`变量而重新创建一个 }]);
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
controller:
http://stackoverflow.com/questions/19981627/setting-scope-property-with-ng-init-doesnt-work
假设你的
controller是这样的: