angular js实现email实时编辑

1.html代码
<html lang="en" ng-app="myApp">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <div ng-controller="MyController">
        <input ng-model="person.name" type="text" placeholder="your name"/>
        <h1>hello parent {{person.name}}</h1><br />
        <hr />
        <img src="D:\Project\server\src\web\img\test.png" />
        <h2>price:{{price}}</h2><h5>限购五件</h5>
        <button ng-click="add(1)">+</button>
        <button ng-click="subtract(1)">-</button>
        <h4>current count:{{total}}</h4>
        {{timenow}}
        <div ng-controller="MyControllerSon">
            <button ng-click="sayhello()">say hello</button>
            <h2>hello 子控制器 {{person.name}}</h2>
            <input ng-model="to" type="text" placeholder="Recipient" />
            <textarea ng-model="emailBody"></textarea>
            <pre>{{previewText}}</pre>
        </div>
    </div>
</body>
</html>
2.js代码
<!DOCTYPE html>
<script src="js/angular.js"></script>
<!--<script>
    // var app = angular.module('app')
    //$scope.i = 0;
    //$scope.j = 188;
    //$scope.priceClick = function()
    //{
    //    i++;
    //};
</script>-->
<script>
    var app = angular.module('myApp', []);
    app.controller('MyController', function ($scope) {
        $scope.person = {name:'weijie'};
        $scope.counter = 0;
        $scope.price = 199;
        $scope.total = 0;
        $scope.clock = { now: new Date() };
        $scope.add = function (x)
        {
            if ($scope.counter < 5)
            {
                $scope.counter = $scope.counter + x;
                $scope.total = $scope.counter * $scope.price;
            }
        };
        $scope.subtract = function (x)
        {
            if ($scope.counter > 0)
            {
                $scope.counter = $scope.counter - x;
                $scope.total = $scope.counter * $scope.price;
            }
        };
            var updateClock = function()
            {
                $scope.clock.now = new Date();
                $scope.timenow = deal($scope.clock.now);


            };
            setInterval(function()
            {
                $scope.$apply(updateClock)
            }, 1000);
            var deal = function (x) {
                return x.toDateString().replace(x.getYear(), "") + x.toTimeString().replace("UTC+0800", "");
            };
    });
    app.controller('MyControllerSon', function ($scope,$interpolate) {
        $scope.sayhello = function () {
            $scope.person.name = 'rose';
        };
        $scope.$watch('emailBody', function(body) 
        {
            if (body) {
                var template = $interpolate(body);
                $scope.previewText =
                template({ to: $scope.to });
            }
         });
    });
</script>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值