簡體   English   中英

AngularJS自定義指令不適用於Handlebars模板

[英]AngularJS custom directive does not work with in Handlebars template

這是有效的代碼:

 <select-city country="US"></select-city>

這是無效的代碼:

 <select-city country="\{{country}}"></select-city>

為了進行測試,我這樣做了:

\{{country}} 

它可以正確打印美國。

注意:我必須使用\\因為我使用的是Handlebars模板。

您需要更改此行:

<select-city country="\{{country}}"></select-city>

要以下內容:

<select-city country="'\' + {{country}}"></select-city>

如果您需要多次執行此操作,則編寫一個自定義getter以避免在視圖中執行此操作可能會很有趣:

$scope.getCountry = function() {
    return '\\' + $scope.country;
}

在視圖中:

<select-city country="{{getCountry()}}"></select-city>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM