zoukankan      html  css  js  c++  java
  • Angular(ng 作用域和控制器)

    html部分

    .............................................................

    <!doctype html>
    <html ng-app="myApp">
    <head>
    <meta charset="UTF-8">
    <title>ng 作用域和控制器</title>
    </head>
    <body>
    <div ng-controller="Counter">
    <span>输入增量:</span>
    <input type="number" ng-model="change"><hr>
    <span>起始值:</span>
    {{start}}
    <br>
    <span>起始值+增加:</span>
    {{current}}
    <button ng-click='inc()'>累加增量</button>
    <button ng-click='dec()'>累减增量</button><hr>
    <span>与起始值比较:</span>
    {{difference}}
    </div>
    </body>

    <script src="js/angular-1.3.0.js"></script>
    <script src="js/作业1_scope和控制器.js"></script>
    </html>
    ................................................................................................
    Js部分

    myApp=angular.module("myApp",[]);
    myApp.controller("Counter",function ($scope) {
    $scope.start=200;
    $scope.change=1;

    $scope.inc=function () {
    $scope.change++;
    $scope.current= $scope.start+$scope.change;
    $scope.difference=$scope.current-$scope.start;
    },
    $scope.dec=function () {
    $scope.change--;
    $scope.current= $scope.start+$scope.change;
    $scope.difference=$scope.current-$scope.start;
    }
    })
  • 相关阅读:
    过度和动画
    自定义指令
    使用ref操作DOM和过滤器的使用
    计算属性与侦听器
    MVVM设计思想
    vue template
    Vue初探
    npm 6.14 + Babel 7 使用
    5行代码起一个服务
    vue打包后引入js和css用相对路径引入
  • 原文地址:https://www.cnblogs.com/YoogaChan/p/6918307.html
Copyright © 2011-2022 走看看