答案 0 :(得分:1)
可以轻松完成,如下所示:
<div ng-init="data = 'This is initialized in ng-init'">
Variable - {{data}}
</div>
参阅演示here
答案 1 :(得分:0)
试用此代码
$scope.test = '10';
<div ng-controller = "controller" ng-init="test">
或
<div ng-controller="controller" ng-init="test = test">