[Angular] In angular world and out angular world
Angular in and out World
2023-09-14 08:59:21 时间
<html ng-app="nameApp"> <head> <meta charset="utf-8"> <title>Angular.js Example</title> <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js"></script> <script> var nameApp = angular.module('nameApp', []); nameApp.controller('NameCtrl', function ($scope){ $scope.firstName = 'John'; $scope.$watch('lastName', function(newValue, oldValue){ console.log('new value is ' + newValue); }); setTimeout(function(){ $scope.lastName = 'Smith'; $scope.$apply(); /*Without $scope.$apply(), it won't work*/ }, 1000); }); </script> </head> <body ng-controller="NameCtrl"> First name:<input ng-model="firstName" type="text"/> <br> Last name:<input ng-model="lastName" type="text"/> <br> Hello {{firstName}} {{lastName}} </body> </html>
Those pieces is outside angular world, if you don't have $scope.$apply, the lastname won't get updated.
setTimeout(function(){
$scope.lastName = 'Smith';
$scope.$apply(); /*Without $scope.$apply(), it won't work*/
}, 1000);
相关文章
- 怎么组织 Angular 项目 |Top 5 技巧
- 自定义 angular-datetime-picker 格式
- 从 Angular Component 和 Directive 的实例化,谈谈 Angular forRoot 方法的命令由来
- Angular tsconfig.json 文件里的 paths 用途
- Angular 结合 dygraphs 实现 annotation
- Angular SSR 应用的 SEO 实现一个例子 - meta 和 title 元素的赋值
- 使用 Angular Universal 进行服务器端渲染避免 window is not defined 的错误消息
- 【Angular教程】组件动效u002F动态组件u002F视图封装模式
- Angular 应用里 ng-package.json 文件的作用是什么?
- 查询Oracle中执行多列IN查询的技巧(oracle多列in)
- MSSQL条件查询IN机制优化技巧(mssql条件查询in)
- 如何在MySQL中代替IN关键字(mysql中代替in)
- MySQL中IN操作符的长度限制问题(mysql中in长度限制)
- MySQL中的IN语句是否能够走索引(mysql中in走索引么)
- MySQL中使用IN类型参数(mysql中in类型参数)
- MySQL中使用IN操作符的查询效率分析(mysql中in的效率)
- 如何优化MySQL中的IN查询语句(mysql中in怎么优化)
- 探究MySQL中IN表达式的作用及实际应用(mysql中in作用)
- MySQL中的IN关键字有什么含义(mysql中in什么意思)
- 深入探究Mysql中IN与AND逻辑运算的应用(mysql中in与and)
- 以Oracle IN查询精准定位你要的信息(oracle使用in查询)
- Oracle中析研IN函数的功能(oracle中的in函数)
- 利用Oracle中的If In语句减少数据处理时间(oracle中if in)