Angularjs如何自定义一个可输入的下拉框组件

发布时间:2020-12-28 10:20:32 作者:小新
来源:亿速云 阅读:766

小编给大家分享一下Angularjs如何自定义一个可输入的下拉框组件,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

在 angularjs 中自定义一个可输入的下拉框组件,组件的创建及引入如下。

新建 insertSelect.html 文件

<style type="text/css">
    .insert-select {
        position: relative;
    }
 
    .input-box {
        position: absolute;
        height: calc(100% - 4px);
        width: calc(100% - 25px);
        top: 2px;
        left: 2px;
        padding-left: 10px;
        outline: none !important;
        border-radius: 4px !important;
        border: none !important;
    }
 
</style>
 
<!--可输入下拉框-->
<div class="insert-select">
    <select ng-attr-placeholder="{{placeholder}}" class="form-control"
            chosen ng-model="modelData"
            ng-options="item for item in optionList">
        <option value=""></option>
    </select>
 
    <input type="text" class="input-box"
           ng-attr-placeholder="{{placeholder}}"
           ng-model="modelData">
</div>

directive 自定义指令

//可输入select框
angular.module("controllers")
.directive("insertSelect", [function () {
    return {
        restrict: 'AE',
        templateUrl: 'template/common/insertSelect.html',
        scope: {
            modelData: '=modelData',        
            optionList: '=optionList',     
            placeholder: '=placeholder',    //placeholder 可由引入页面传入
        },
        link: function ($scope, $elem) {
            //
        },
        controller: ["$scope", function ($scope) {
 
        }]
    }
}]);

页面引入 insertSelect 组件

<insert-select model-data="formData"
               option-list="successCodeList"
               placeholder="'请选择'">
</insert-select>

看完了这篇文章,相信你对“Angularjs如何自定义一个可输入的下拉框组件”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

推荐阅读:
  1. Vue可自定义tab组件用法实例
  2. vue如何实现可搜索下拉框功能

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

angularjs angularj

上一篇:JavaScript中比较对象的方式有哪些

下一篇:MySQL语句加锁的示例分析

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》