【发布时间】:2016-04-26 14:41:38
【问题描述】:
我有一个自定义指令,我希望能够将过滤器名称传递给它。然后该过滤器将在我的模板中使用。这是我到目前为止得到的:
指令:
angular.module('forecastDirective', [])
.directive('forecast', ['appConfig', function(appConfig) {
return {
templateUrl: appConfig.directivesRoot + 'templates/forecast.html',
replace: true,
scope: {
weatherObject: "=",
convertToDate: "&",
filterTemp: "@",
dateFormat: "@",
},
}
}]);
模板:
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{{ convertToDate({ dt: weatherObject.dt }) | date: dateFormat }}</h3>
</div>
<div class="panel-body">
Daytime temperature: {{ weatherObject.temp.day | filterTemp }}
</div>
</div>
【问题讨论】:
-
正如@AmyBlankenship 的回答所述,您不需要将其注入或传递给指令定义。它应该对模板可用。如果不是,那么您可能需要检查该过滤器是否可用于定义您的指令的模块。
标签: angularjs filter directive