Home  >  Article  >  Web Front-end  >  Sharing of input examples in angularJS_AngularJS

Sharing of input examples in angularJS_AngularJS

WBOY
WBOYOriginal
2016-05-16 16:15:03941browse

Here is an example of how to use the input command

Copy code The code is as follows:





Untitled Document









<script><br> var app = angular.module('Demo', [], angular.noop);<br> ​ app.directive('test', function(){<br> //The link of the input command has a fourth parameter, $ctrl has some methods, you can use it yourself<br> var link = function($scope, $element, $attrs, $ctrl){<br> console.log( $ctrl )<br> $ctrl.$formatters.push(function(value){<br>             return value.join(',');<br> });<br> $ctrl.$parsers.push(function(value){<br>             return value.split(',');<br> });<br> }<br> Return {compile: function(){return link},<br>                require: 'ngModel',<br>               restrict: 'A'}<br> });<br> app.controller('TestCtrl', function($scope){<br> $scope.a = [];<br> //$scope.a = [1,2,3];<br> $scope.show = function(v){<br> console.log(v);<br> }<br> });<br> </script>

The code is very simple, friends can expand it freely, I hope you can like it

Statement:
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