加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

数组 – 将数组通过属性传递给AngularJS指令

发布时间:2020-12-17 08:56:06 所属栏目:安全 来源:网络整理
导读:我目前有一个问题,通过该指令的属性传递数组到指令。我可以读它作为一个字符串,但我需要它作为一个数组,所以这是我想出了,但它不工作。帮助任何人?提前提前 Javascript :: app.directive('post',function($parse){ return { restrict: "E",scope:{ titl
我目前有一个问题,通过该指令的属性传递数组到指令。我可以读它作为一个字符串,但我需要它作为一个数组,所以这是我想出了,但它不工作。帮助任何人?提前提前

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" ... >

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读