work hard work smart

专注于Java后端开发。 不断总结,举一反三。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Angularjs 事件指令

Posted on 2017-07-20 09:56  work hard work smart  阅读(200)  评论(0编辑  收藏  举报

1.  点击事件

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" src="angular.min.js"></script>
</head>
<body>
<div ng-app="myApp">

    <div ng-controller="firstController">
        <div ng-click="run()">点击</div>
    </div>
</div>
<script type="text/javascript">
    var app = angular.module("myApp", []);
    app.controller('firstController',function($scope){
        $scope.text='phonegap中文网';

        $scope.run=function(){

            alert('run');
            console.log('run');
        }
    });
</script>

</body>
</html>

  

 

2. 样式 ng-class

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" src="angular.min.js"></script>
    <style>
        .red{background:red;}
        .yellow{background:yellow;}
    </style>
</head>
<body>
<div ng-app="myApp">

    <div ng-controller="firstController">
        <div ng-click="run()">点击</div>
        <div ng-class="{red:true}">{{text}}</div>
    </div>
</div>
<script type="text/javascript">
    var app = angular.module("myApp", []);
    app.controller('firstController',function($scope){
        $scope.text='phonegap中文网';

        $scope.run=function(){

            alert('run');
            console.log('run');
        }
    });
</script>

</body>
</html>