第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在AngularJS中使用自己的作用域*從自定義指令*中訪問父作用域?

如何在AngularJS中使用自己的作用域*從自定義指令*中訪問父作用域?

慕桂英3389331 2019-07-09 16:20:16
如何在AngularJS中使用自己的作用域*從自定義指令*中訪問父作用域?我正在尋找在指令中訪問“父”范圍的任何方式。任何范圍的組合,轉(zhuǎn)換,要求,從上面?zhèn)魅胱兞?或作用域本身)等等。我完全愿意向后彎曲,但我想避免一些完全不牢靠或無法維護(hù)的東西。例如,我知道我現(xiàn)在可以通過$scope從預(yù)鏈接參數(shù)中迭代它的$sibling用于查找概念性“父”的范圍。我真正想要的是$watch父作用域中的表達(dá)式。如果我能做到的話,我就能完成我在這里想要做的事情:AngularJS-如何用變量呈現(xiàn)部分?重要音符該指令必須在同一父范圍內(nèi)可重用。因此,默認(rèn)行為(作用域:false)對(duì)我不起作用。我需要指令的每個(gè)實(shí)例都有一個(gè)單獨(dú)的作用域,然后我需要$watch駐留在父作用域中的變量。代碼示例值1000個(gè)單詞,因此:app.directive('watchingMyParentScope', function() {     return {         require: /* ? */,         scope: /* ? */,         transclude: /* ? */,         controller: /* ? */,         compile: function(el,attr,trans) {             // Can I get the $parent from the transclusion function somehow?             return {                 pre: function($s, $e, $a, parentControl) {                     // Can I get the $parent from the parent controller?                     // By setting this.$scope = $scope from within that controller?                     // Can I get the $parent from the current $scope?                     // Can I pass the $parent scope in as an attribute and define                     // it as part of this directive's scope definition?                     // What don't I understand about how directives work and                     // how their scope is related to their parent?                 },                 post: function($s, $e, $a, parentControl) {                     // Has my situation improved by the time the postLink is called?                 }             }         }     };});
查看完整描述

3 回答

?
搖曳的薔薇

TA貢獻(xiàn)1793條經(jīng)驗(yàn) 獲得超6個(gè)贊

下面是我曾經(jīng)使用過的一個(gè)技巧:創(chuàng)建一個(gè)“虛擬”指令來保存父作用域,并將其放置在所需指令之外的某個(gè)地方。類似于:

module.directive('myDirectiveContainer', function () {
    return {
        controller: function ($scope) {
            this.scope = $scope;
        }
    };});module.directive('myDirective', function () {
    return {
        require: '^myDirectiveContainer',
        link: function (scope, element, attrs, containerController) {
            // use containerController.scope here...
        }
    };});

然后

<div my-directive-container="">
    <div my-directive="">
    </div></div>

也許不是最優(yōu)雅的解決方案,但它完成了任務(wù)。


查看完整回答
反對(duì) 回復(fù) 2019-07-09
  • 3 回答
  • 0 關(guān)注
  • 871 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)