Heb*_*rLZ 55 arrays parsing attributes directive angularjs
我通过该指令的属性将数组传递给指令时遇到问题.我可以把它读作一个字符串,但我需要它作为一个数组,所以这是我想出来但它不起作用.帮助任何人?事先说
使用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)
}
}
}
Run Code Online (Sandbox Code Playgroud)
HTML ::
<post title="sample title" tags="['HTML5', 'AngularJS', 'Javascript']" ... >
Run Code Online (Sandbox Code Playgroud)
Ale*_*orn 60
如果从范围访问此数组,即加载到控制器中,则只需传递变量的名称:
指示:
scope:{
title: "@",
author: "@",
content: "@",
cover: "@",
date: "@",
tags: "="
},
Run Code Online (Sandbox Code Playgroud)
模板:
<post title="sample title" tags="arrayName" ... >
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
64840 次 |
| 最近记录: |