[英]How do you access angular directive isolated scope variables in link?
這是我的html
<test something="hey"> </test>
這是我的指令
app.directive('test', ['', function (l) {
return {
restrict: 'EC',
replace: true,
require: 'ngModel',
scope: {
something: '@'
},
templateUrl: '<div something="none"></div>',
link: function (scope, elm) {
// how do I access something in link?
反正我有可以訪問的范圍變量something
在鏈接功能
scope.something // doesn't return anything
在父范圍內是否有一個名為hey
的變量? 我相信您正在傳遞變量hey
而不是字符串(我假設您正在嘗試傳遞字符串)。 您應該嘗試這樣:
<test something="'hey'"> </test>
要么
<test something="{{hey}}"> </test>
指令綁定總是很棘手, 這是一本好書。
讓我知道它是否有效! :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.