我目前有一个问题,通过该指令的属性传递数组到指令。我可以读它作为一个字符串,但我需要它作为一个数组,所以这是我想出了,但它不工作。帮助任何人?提前提前
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']" ... >
如果你从你的范围访问这个数组,即加载在控制器中,你可以传递变量的名称:
原文链接:https://www.f2er.com/angularjs/146283.htmlBinding array to directive variable in AngularJS
指示:
scope:{ title: "@",date: "@",tags: "=" },
模板:
<post title="sample title" tags="arrayName" ... >