如何使用AngularJS在ng-init中传递范围变量 [英] How to pass scope variable in ng-init using AngularJS
本文介绍了如何使用AngularJS在ng-init中传递范围变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在将范围声明的变量传递给ng-init时遇到问题:
I have problem passing the variable declared from the scope to ng-init:
到目前为止,我有类似这样的事情:
so far I have something like this:
$scope.x = '10';
<div ng-controller = "controller" ng-init="function(x)">
如何从ng-init函数中的范围传递x var?
How do I pass x var from the scope inside ng-init function?
推荐答案
很多人会告诉你不要这样做(如文档中所述: https://docs.angularjs.org/api/ng/directive/ngInit )。
A lot of people will tell you you shouldn't do this (as mentioned in the docs here: https://docs.angularjs.org/api/ng/directive/ngInit).
至于实际执行....
As for actually doing it....
<div ng-controller="controller" ng-init="x = x">
这篇关于如何使用AngularJS在ng-init中传递范围变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文