AngularJS--day04-列表点击事件-事件的监听

<!DOCTYPE html>
<html ng-app='app' ng-controller='mainController'>
    <head>
        <meta charset="utf-8">
        <title ng-bind='mianTitle'></title>
    </head>
    <body>
        <button ng-click='func()'>点我调用controller中的函数</button>
        <p ng-show='showFlag'>{{msg}}</p>
        <button ng-click='clickHandler()'>测试按钮</button>
        <ul>
            <li ng-repeat='li_info in infos track by $index' ng-click='li_click($index)'>{{li_lifo}}</li>
        </ul>
        <script src="angular.js"></script>
        <script>
            var app = angular.module('app',[]);
            app.controller('mainController',['$scope',function($scope){
                $scope.mainTitle = 'lessonday5_事件的监听';
                $scope.func = function(){
                    console.log('here is a func');
                };
                //评论点击隐藏收起功能额
                $scope.showFlag = true;//默认显示
                $scope.msg = 'here is a test msg';
                $scope.li_infos = ['哈哈','啦啊','顶顶'];
                $scope.li_click = function (index){//传进来的是第几个元素下标
                    console.log('点击的li的内容'+$scope.li_infos[index]);
                    $scope.showFlag = !$scope.showFlag;
                };
            }]);
        </script>
    </body>
</html>

 

posted @ 2019-08-28 14:31  小白咚  阅读(567)  评论(0编辑  收藏  举报