Example of input in angularJS: angularjsinput
Here is an example of how to use an input command.
Copy codeThe Code is as follows:
<! Doctype html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> untitled document </title>
</Head>
<Script src = "http: // localhost: 81/js/jquery. js">
</Script>
<Script src = "http: // localhost: 81/js/angular. min. js">
</Script>
<Body ng-app = "Demo">
<Div ng-controller = "TestCtrl">
<Input type = "text" ng-model = "a" test/>
<Button ng-click = "show (a)"> View </button>
</Div>
</Body>
<Script>
Var app = angular. module ('Demo', [], angular. noop );
App. directive ('test', function () {<br> // the link of the input command has the fourth parameter. You can use $ ctrl in some ways.
Var link = function ($ scope, $ element, $ attrs, $ ctrl ){
Console. log ($ ctrl)
$ Ctrl. $ formatters. push (function (value ){
Return value. join (',');
});
$ Ctrl. $ parsers. push (function (value ){
Return value. split (',');
});
}
Return {compile: function () {return link },
Require: 'ngmodel ',
Restrict: 'A '}
});
App. controller ('testctrl ', function ($ scope ){
$ Scope. a = [];
// $ Scope. a = [1, 2, 3];
$ Scope. show = function (v ){
Console. log (v );
}
});
</Script>
</Html>
The code is very simple. I hope you can enjoy it with free extension.