1
什麼,我試圖做的是創建下面的標記:簡單的指令來工作就像一個綁定表達式
<current-user />
這個指令應該簡單地注入當前用戶名稱就像一個綁定表達式{{} currentUser.name }
這裏是我,但我在最後的caret
失去了我的跨度標籤:
HTML:
<a href="" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-user"></i>
<current-user />
<span class="caret"></span>
</a>
的Javascript:
app.directive('currentUser', function ($rootScope, auth) {
return {
restrict: 'E',
transclude: true,
compile: function (elem) {
$rootScope.$watch('auth.profile', function (profile) {
if (profile) {
elem.html(profile.email);
}
});
}
}
});
任何幫助,將不勝感激
啊...'$ rootScope。在'compile'指令$ watch',爲什麼呢? &我也可以知道爲什麼'elem.html'作爲電子郵件將是簡單的文本.. –
假裝我沒有使用rootcope和用戶名可能是任何東西。我只是選擇電子郵件。 – Marco