Angular 学习笔记——$interpolate

<!DOCTYPE HTML>
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script src="angular.min.js"></script>
<script>
    var m1 = angular.module('myApp',[]);
    m1.controller('may',['$scope','$interpolate',function ($scope,$interpolate){
        $scope.$watch('key',function(newVal){
            if(newVal){
                var temp = $interpolate(newVal);
                $scope.showtime = temp({name:$scope.name})
            }
        });
        $scope.$watch('name',function(newVal){
            if(newVal){
                var temp = $interpolate(newVal);
                $scope.showtime = temp({name:$scope.name})
            }
        })
    }])
</script>
</head>

<body ng-controller='may'>
    <input type="text" ng-model='name'>
    <textarea ng-model='key'></textarea>
    <p>{{showtime}}</p>
</body>
</html>

 

posted @ 2015-12-07 22:45  mayufo  阅读(245)  评论(0编辑  收藏  举报