【发布时间】:2023-03-19 20:37:01
【问题描述】:
假设我有以下指令:
.directive("counter", function () {
return {
restrict: "E",
scope:{
bindModel:'=ngModel'
},
templateUrl: "/directives/countertemplate.html"
和模板:
<div id="counter" ng-class="{true: 'twitter-counter'}[bindModel.length > 140]">
{{140 - bindModel.length}}
</div>
有没有办法让我知道传递给指令的模型名称:
<counter ng-model="twitterPost"></counter>
例如,我想从模板的上下文中知道“twitterPost”被发送到模板,所以我可以执行与“facebookPost”不同的逻辑集
【问题讨论】:
-
使用不同的属性
标签: angularjs angularjs-directive angularjs-scope directive angular-ngmodel