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

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

angularjs directive link 屬性 問題?

angularjs directive link 屬性 問題?

元芳怎么了 2019-02-04 10:06:02
angular.module('docsTransclusionExample', []).controller('Controller', ['$scope', function($scope) {  $scope.name = 'Tobias';}]).directive('myDialog', function() {  return {    restrict: 'E',    transclude: true,    scope: {},    templateUrl: 'my-dialog.html',    link: function (scope, element) {      scope.name = 'Jeff';    }  };});這個(gè)在官網(wǎng)上的directive代碼,link函數(shù)起到的什么作用,解釋有點(diǎn)費(fèi)解,然后其中有三個(gè)參數(shù)scope:is an Angular scope object.element: is the jqLite-wrapped element that this directive matches.attrs: is a hash object with key-value pairs of normalized attribute names and their corresponding attribute values.這個(gè)用法是怎樣的,scope好像就是return中得scope屬性。。
查看完整描述

2 回答

?
至尊寶的傳說

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

首先我們先來聊聊你列出的directive中的幾個(gè)屬性:

  1. restrict
    E: 表示該directive僅能以element方式使用,即:<my-dialog></my-dialog>
    A: 表示該directive僅能以attribute方式使用,即:<div my-dialog></div>
    EA: 表示該directive既能以element方式使用,也能以attribute方式使用

  2. transclude
    你的directive可能接受頁面上的其他html內(nèi)容時(shí)才會(huì)用到,建議你先去掉該參數(shù)。有些高階了。

  3. scope
    當(dāng)你寫上該屬性時(shí),就表示這個(gè)directive不會(huì)從它的controller里繼承$scope對(duì)象,而是會(huì)重新創(chuàng)建一個(gè)。

  4. templateUrl
    你的directive里的html內(nèi)容

  5. link
    可以簡單理解為,當(dāng)directive被angular 編譯后,執(zhí)行該方法

這里你說的沒錯(cuò),link中的第一個(gè)參數(shù)scope基本上就是你說的上面寫的那個(gè)scope。

element簡單說就是$('my-dialog')

attrs是個(gè)map,內(nèi)容是你這個(gè)directive上的所有屬性,例如:你在頁面上如果這樣寫了directive:

<my-dialog type="modal" animation="fade"></my-dialog>

attrs就是:
{
type: 'modal',
animation: 'fade'
}


查看完整回答
反對(duì) 回復(fù) 2019-03-17
  • 2 回答
  • 0 關(guān)注
  • 509 瀏覽

添加回答

舉報(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)