Home > Web Front-end > JS Tutorial > body text

Angularjs customizes an input drop-down box component (code example)

青灯夜游
Release: 2021-02-01 11:46:30
forward
2756 people have browsed it

The following article will introduce to you AngularjsHow to customize an input drop-down box component. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Angularjs customizes an input drop-down box component (code example)

Related recommendations: "angularjs tutorial"

Customize an input drop-down box component in angularjs, and create the component and introduced as follows.

New insertSelect.html file

<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>
Copy after login

directive Custom directive

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

The page introduces the insertSelect component

<insert-select model-data="formData"
               option-list="successCodeList"
               placeholder="&#39;请选择&#39;">
</insert-select>
Copy after login

For more programming-related knowledge, please visit: Programming Teaching! !

The above is the detailed content of Angularjs customizes an input drop-down box component (code example). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!