首页 > Web开发 > 详细

AngularJS自定义表单控件

时间:2015-07-05 23:55:39      阅读:495      评论:0      收藏:0      [点我收藏+]
<!doctype html>
<html ng-app="myApp">
<head>
    <script src="G:\\Source\\Repos\\GWD\\Gridsum.WebDissector.Website.ZC\\Gridsum.WebDissector.Website.ZC\\Pages\\dist\\assets\\lib\\angularjs\\angular.js"></script>
    <script type="text/javascript">
        angular.module(‘myApp‘, []).directive(‘contenteditable‘, function () {
            return {
                require: ‘ngModel‘,
                link: function (scope, elm, attrs, ctrl) {
                    // view -> model
                    elm.bind(‘blur‘, function () {
                        scope.$apply(function () {
                            ctrl.$setViewValue(elm.html());
                        });
                    });
                    // model -> view
                    ctrl.$render = function (value) {
                        elm.html(value);
                    };
                    // load init value from DOM
                    ctrl.$setViewValue(elm.html());
                }
            };
        });
    </script>
</head>
<body>
    <div contenteditable="true" ng-model="content" title="Click to edit">Some</div>
<pre>model = {{content}}</pre>
    <style type="text/css">
        div[contentEditable] {
            cursor: pointer;
            background-color: #D0D0D0;
        }
    </style>
</body>
</html>

  

AngularJS自定义表单控件

原文:http://www.cnblogs.com/chengshuiqiang/p/4623273.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!