angularJS 入门基础(7)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>angular</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <script src=""></script>
    <script src=""></script>
    <link href="">
    <script src="" type="text/javascript"></script>
</head>
<body ng-app="app">
    <script type="text/javascript">
           var app = angular.module("app",[]);
    </script>
    <div>
        <div>
            使用模板
        </div>
        <div ng-controller="ngTpl">
                        <!---这个type要声明准确-->
            <script type="text/ng-template">
                {{ver}}
            </script>
                            <!---tpl是一个定值不是变量,要给变量要在scope中进行定义---->
            <div ng-include src="'https://www.jb51.net/article/tpl'"></div>
            <div>
                <button ng-click="chan()">change</button>
            </div>
        </div>
        <script type="text/javascript">
            app.controller("ngTpl", function($scope) {
                function hehe(str) {
                    str = _.shuffle(str);
                    return str.join("")
                };
                $scope.ver = "var——ver--heehe";
                $scope.chan = function() {
                    $scope.ver = hehe( $scope.ver );
                };
            });
        </script>
    </div>
</body>
</html>

如何使用$scope.$watch实时改变绑定界面的模板:

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgfxjj.html