• angularjs中的数据绑定


    这是一个最简单的angularjs的例子,关于数据绑定的,大家可以执行一下,看看效果

    <html ng-app>
    <head>
    <title>angularjs-include</title>
    <script type="text/javascript" src="js/angular/angular.min.js"></script>
    </head>
    <body>
    <input type="text" ng-model="name" value="" /><br />
    <div>Hello,{{name}}</div>
    </body>
    </html>

    关于数据双向绑定,有时候不需要实时同步,比如当输入框失去焦点的时候才去更新div里面的内容,这里可以用上ng-model-options属性来解决,将上面的代码稍做修改:

    <html ng-app>
    <head>
    <title>angularjs-include</title>
    <script type="text/javascript" src="js/angular/angular.min.js"></script>
    </head>
    <body>
    <input type="text" ng-model="name" value="" ng-model-options="{ updateOn: 'blur' }" /><br />
    <div>Hello,{{name}}</div>
    </body>
    </html>

     或者改为每隔1秒来更新:

    <html ng-app>
    <head>
    <title>angularjs-include</title>
    <script type="text/javascript" src="js/angular/angular.min.js"></script>
    </head>
    <body>
    <input type="text" ng-model="name" value="" ng-model-options="{ debounce: {default:1000} }" /><br />
    <div>Hello,{{name}}</div>
    </body>
    </html>
  • 相关阅读:
    MySql
    Zookeeper
    Kafka
    Mybatis
    Spring/Spring MVC
    Spring Boot/Spring Cloud
    网络
    设计模式
    Strassen algorithm(O(n^lg7))
    dynamic programming:find max subarray
  • 原文地址:https://www.cnblogs.com/modou/p/5174267.html
Copyright © 2020-2023  润新知