gpt4 book ai didi

javascript - 从指令范围变量获取引用

转载 作者:行者123 更新时间:2023-11-28 07:21:58 25 4
gpt4 key购买 nike

<div ng-controller="myController">
<div some-directive ng-model="some-directive-scope.variable>
{{ some-directive-scope.variable }}
</div>
<p ng-bind="some-directive-scope.variable"></p>
</div>

我正在使用第三方库,它不允许我访问特定指令范围的变量。有没有办法让我的 Controller 可以获取引用或设置值?

最佳答案

您可以使用ng-init将其绑定(bind)到外部作用域中定义的变量。例如:

Controller :

function myController($scope) {
//Due to inheritance rules between scopes we must place the scope variable
//in a container and not directly on the scope, otherwise it won't work
$scope.scopes = {};
}

模板:

<div ng-controller="myController">
<div some-directive ng-model="some-directive-scope.variable" ng-init="scope.some-directive = some-directive-scope">
{{ some-directive-scope.variable }}
</div>
<p ng-bind="scopes.some-directive.variable"></p>
</div>

关于javascript - 从指令范围变量获取引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30202674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com