javascript - angularjs 我自定义了一个指令,想在同一个页面复用
PHP中文网
PHP中文网 2017-04-11 12:33:29
[JavaScript讨论组]

自定义了一个指令,想在一个页面中多次使用,每个指令传入的参数不同,如何让他获取对应参数取得的值
html


js
app.directive('selectOption',function($http){

return{
    restrict:'E',
    scope :'' ,
    link:function(scope, element, attrs) {
        scope.title = attrs.title;
        scope.grup = attrs.grup;
        scope.list = attrs.grup;
        var data = {
                 'groupName':attrs.title
        };
        scope.ceshi = function(a){
            alert(a);
        }
        $http.post('/datadicItem/findItemsByGroupName',data,postCfg)
             .success(function(resp){
                 // debugger
                 scope.list = resp;
                 console.log(scope.list);
             });
    },
    template:'

'+ ' '+ '  {{title}}'+ ''+''+ ''+ ''+ ''+ '

', replace:true, };

});

PHP中文网
PHP中文网

认证0级讲师

全部回复(2)
阿神

option选项里的具体内容 如果是经常变的 要向后端发起请求获取 如果是性别只有男女这种 就可以写在controller里面

阿神

下面具体代码没看完,就独立指令,上面应该这么写:

return {
    restrict : 'E',
    scope : {
        title : '=',
        grup  : '='
    },
    link : function( scope, tElement, tAttrs ){
        // 这样数据才是双向绑定的~
        // scope.title
        // scope.grup
        ...
    }
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号