我目前有一个问题,通过该指令的属性传递数组到指令。我可以读它作为一个字符串,但我需要它作为一个数组,所以这是我想出了,但它不工作。帮助任何人?提前提前
Javascript ::
app.directive('post',function($parse){ return { restrict: "E",scope:{ title: "@",author: "@",content: "@",cover: "@",date: "@" },templateUrl: 'components/postComponent.html',link: function(scope,element,attrs){ scope.tags = $parse(attrs.tags) } } }
HTML ::
<post title="sample title" tags="['HTML5','AngularJS','Javascript']" ... >
如果你从你的范围访问这个数组,即加载在控制器中,你可以传递变量的名称:
Binding array to directive variable in AngularJS
指示:
scope:{ title: "@",date: "@",tags: "=" },
模板:
<post title="sample title" tags="arrayName" ... >
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。