Example of input in angularJS: angularjsinput

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.