<a href='https://github.com/angular/angular.js/edit/v1.8.x/docs/content/guide/migration.ngdoc?message=docs(guide%2FMigrating from Previous Versions)%3A%20describe%20your%20change...' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit"> </i>Improve this Doc</a>
<h1 id="migrating-an-app-to-a-newer-version">Migrating an App to a newer version</h1>
<p>Minor version releases in AngularJS introduce several breaking changes that may require changes to your
application's source code; for instance from 1.0 to 1.2 and from 1.2 to 1.3.</p>
<p>Although we try to avoid breaking changes, there are some cases where it is unavoidable:</p>
<ul>
<li>AngularJS has undergone thorough security reviews to make applications safer by default,
which drives many of these changes.</li>
<li>Several new features, especially animations, would not be possible without a few changes.</li>
<li>Finally, some outstanding bugs were best fixed by changing an existing API.</li>
</ul>
<h2 id="migrating-from-1-7-to-1-8">Migrating from 1.7 to 1.8</h2>
<p>Generally updating to 1.8.0 from 1.7.x should be a straightforward process and is highly recommended.
AngularJS 1.8 is a breaking change release from 1.7 to mitigate a security issue.</p>
<p>JqLite no longer turns XHTML-like strings like <code><div /><span /></code> to sibling elements when not in XHTML
mode: <code><div></div><span></span></code>.
Instead it will leave the elements alone. In non-XHTML mode the browser will convert these to nested
elements: <code><div><span></span></div></code>.</p>
<p>This is a security fix to avoid an XSS vulnerability if a new jqLite element is created from a
user-controlled HTML string. If you must have this functionality and understand the risk involved
then it is posible to restore the original behavior by calling</p>
<pre><code class="lang-js">angular.UNSAFE_restoreLegacyJqLiteXHTMLReplacement();
</code></pre>
<p>But you should adjust your code for this change and remove your use of this function as soon as
possible.</p>
<p>Note that this only patches jqLite. If you use jQuery 3.5.0 or newer, please read the
<a href="https://jquery.com/upgrade-guide/3.5/">jQuery 3.5 upgrade guide</a> for more details about the workarounds.</p>
<h2 id="migrating-from-1-6-to-1-7">Migrating from 1.6 to 1.7</h2>
<p>AngularJS 1.7 contains bug fixes and features to AngularJS core and its external modules, some of
which contain breaking changes. However, most of these address internal behavior and not APIs, and
should not affect many applications.
Additionally, we have removed some long-deprecated modules and APIs.</p>
<p>The most notable changes are:</p>
<ul>
<li><p><code>$resource</code> has now support for request and requestError interceptors</p>
</li>
<li><p>Several deprecated features have been removed:</p>
<ul>
<li>the <code>$controllerProvider.allowGlobals()</code> flag</li>
<li>the <code>$compileProvider.preAssignBindingsEnabled()</code> flag</li>
<li>the <code>angular.lowercase</code> and <code>angular.uppercase</code> methods</li>
<li>the <code>$cookieStore</code> service from the <code>ngCookies</code> module</li>
<li>the <code>ngClick</code> override directive and corresponding services from the <code>ngTouch</code> module</li>
<li>the complete <code>ngScenario</code> module</li>
</ul>
</li>
</ul>
<p>Please note that feature development (without breaking changes) has happened in parallel on the
1.6.x branch, so 1.7 doesn't contain many new features, but you may still benefit from those
features that were added (with possible BCs), bugfixes, and a few smaller performance improvements.</p>
<p><br />
Below is the full list of breaking changes:</p>
<p><br />
<a name="migrate1.6to1.7-ng-directives"></a></p>
<h3 id="core-_directives_">Core: <em>Directives</em></h3>
<h4 id="-form-"><strong>form</strong></h4>
<p><strong>Due to <a href="https://github.com/angular/angular.js/commit/223de59e988dc0cc8b4ec3a045b7c0735eba1c77">223de5</a></strong>,
forms will now set <code>$submitted</code> on child forms when they are submitted.
For example:</p>
<pre><code><form name="parentform" ng-submit="$ctrl.submit()">
<ng-form name="childform">
<input type="text" name="input" ng-model="my.model" />
</ng-form>
<input type="submit" />
</form>
</code></pre>
<p>Submitting this form will set <code>$submitted</code> on "parentform" and "childform".
Previously, it was only set on "parentform".</p>
<p>This change was introduced because mixing <code>form</code> and <code>ngForm</code> does not create
logically separate forms, but rather something like input groups.
Therefore, child forms should inherit the submission state from their parent form.</p>
<h4 id="-input-radio-and-input-checkbox-"><strong>input[radio]</strong> and <strong>input[checkbox]</strong></h4>
<p><strong>Due to <a href="https://github.com/angular/angular.js/commit/656c8fa8f23b1277cc5c214c4d0237f3393afa1e">656c8f</a></strong>,
<code>input[radio]</code> and <code>input[checkbox]</code> now listen to the "change" event instead of the "click" event.
Most apps should not be affected, as "change" is automatically fired by browsers after "click"
happens.</p>
<p>Two scenarios might need migration:</p>
<ul>
<li>Custom click events:</li>
</ul>
<p>Before this change, custom click event listeners on radio / checkbox would be called after the
input element and <code>ngModel</code> had been updated, unless they were specifically registered before
the built-in click handlers.
After this change, they are called before the input is updated, and can call
<code>event.preventDefault()</code> to prevent the input from updating.</p>
<p>If an app uses a click event listener that expects <code>ngModel</code> to be updated when it is called, it now
needs to register a change event listener instead.</p>
<ul>
<li>Triggering click events:</li>
</ul>
<p>Conventional trigger functions:</p>
<p>The change event might not be fired when the input element is not attached to the document. This
can happen in <strong>tests</strong> that compile input elements and trigger click events on them. Depending on
the browser (Chrome and Safari) and the trigger method, the change event will not be fired when the
input isn't attached to the document.</p>
<p>Before:</p>
<pre><code class="lang-js">it('should update the model', inject(function($compile, $rootScope) {
var inputElm = $compile('<input type="checkbox" ng-model="checkbox" />')($rootScope);
inputElm[0].click(); // Or different trigger mechanisms, such as jQuery.trigger()
expect($rootScope.checkbox).toBe(true);
});
</code></pre>
<p>With this patch, <code>$rootScope.checkbox</code> might not be true, because the click event hasn't triggered
the change event. To make the test, work append <code>inputElm</code> to the app's <code>$rootElement</code>, and the
<code>$rootElement</code> to the <code>$document</code>.</p>
<p>After:</p>
<pre><code class="lang-js">it('should update the model', inject(function($compile, $rootScope, $rootElement, $document) {
var inputElm = $compile('<input type="checkbox" ng-model="checkbox" />')($rootScope);
$rootElement.append(inputElm);
$document.append($rootElement);
inputElm[0].click(); // Or different trigger mechanisms, such as jQuery.trigger()
expect($rootScope.checkbox).toBe(true);
});
</code></pre>
<h4 id="-input-number-"><strong>input[number]</strong></h4>
<p><strong>Due to <a href="https://github.com/angular/angular.js/commit/aa3f951330ec7b10b43ea884d9b5754e296770ec">aa3f95</a></strong>,
<code>input[type=number]</code> with <code>ngModel</code> now validates the input for the <code>max</code>/<code>min</code> restriction against
the <code>ngM
angular-1.8.0.zip
需积分: 0 98 浏览量
更新于2024-04-25
收藏 7.41MB ZIP 举报
Angular.js 是一款强大的前端JavaScript框架,由Google维护,主要用于构建单页应用(SPA,Single-Page Applications)。在本文中,我们将深入探讨Angular.js 1.8.0版本的关键特性和重要知识点。
一、Angular.js 框架概述
Angular.js 通过MVC(Model-View-Controller)架构模式,使得前端开发更为结构化和高效。它引入了数据绑定、依赖注入、指令系统等概念,极大地简化了DOM操作和业务逻辑的耦合。
二、版本1.8.0特性
1. **兼容性**:Angular.js 1.8.0是1.x系列的一个稳定版本,旨在保持与旧版API的向后兼容,允许开发者逐步迁移到Angular(2+)或其他现代框架。
2. **安全更新**:此版本可能包含安全修复,确保应用免受潜在的攻击,保护用户数据的安全。
3. **错误修复**:对已知问题进行修复,提高框架的稳定性和性能。
三、核心概念
1. **数据绑定**:双向数据绑定是Angular.js的核心特性,使得视图和模型之间的数据自动同步,减少了手动DOM操作。
2. **依赖注入**:Angular.js通过依赖注入(DI)机制管理对象的生命周期和依赖关系,使得代码可测试性更强,模块化程度更高。
3. **指令**:自定义HTML标签或属性,扩展HTML功能,如ng-repeat用于列表渲染,ng-click处理点击事件。
4. **服务**:提供跨组件共享数据和功能的机制,例如$http服务用于Ajax请求,$rootScope是所有控制器共享的全局作用域。
5. **过滤器**:用于格式化显示的数据,如currency、date等,使数据更易于阅读。
四、开发实践
1. **模块化**:通过angular.module创建和组织应用模块,可以更好地管理代码结构。
2. **控制器**:控制应用的业务逻辑,通过$scope对象连接视图和模型。
3. **路由**:使用ngRoute或ui-router实现页面跳转和URL管理,构建多视图应用。
4. **表单处理**:Angular.js提供了内置的表单验证机制,通过ng-model、ng-required等指令实现。
5. **测试**:支持单元测试和端到端测试,如 Karma 和 Protractor 工具。
五、迁移与升级
虽然Angular.js 1.8.0保持了与早期版本的兼容,但Angular(2+)引入了更多现代化的开发理念和工具,如TypeScript支持、组件化开发等。开发者应考虑长远规划,适时将项目迁移到Angular(2+)以获取更多性能提升和新功能。
Angular.js 1.8.0作为1.x系列的最后一个稳定版本,对于那些仍在使用Angular.js 1.x的项目来说,是继续维护和优化的良好选择。然而,随着技术的发展,考虑未来向Angular(2+)的过渡是明智之举。学习和理解Angular.js的核心概念和实践技巧,将有助于你在前端开发领域保持竞争力。

段子手-168
- 粉丝: 5169
最新资源
- 人工智能辅助动画制作流程优化.docx
- 人工智能驱动下的移动门户建设策略及实践案例分析.docx
- 人工智能领域中数学知识的梳理与总结.docx
- 软件项目开发全周期回顾与总结报告.docx
- 深度优化算法在风光储互补电力系统调度中的应用研究.docx
- COMSOL相场法模拟水力压裂与煤层压裂:多场耦合问题及案例指导 全集
- 双馈发电系统:矢量控制算法优化与稳定性分析.docx
- 水面VLC通信系统的自适应对准算法与信号增强策略.docx
- 图扩散增强对比学习系统:算法框架与性能优化研究.docx
- 中考必会几何模型中点四大模型的解析与应用.docx
- 基于红外、可见光双光源的车辆目标检测
- 基于MATLABSimulink的光储一体机Boost-NPC直流侧耦合仿真模型及功率调度控制 · Boost电路
- Python利用古诗词数据库提取的所有宋朝诗人简介
- 三层层级电梯控制系统与MCGS7.7及三菱FX系列PLC联机技术的应用与实现
- 基于Tensorflow2.x开源的项目,比如:目标检测、风格迁移、图像分类、情感分析等等
- 【数控机床领域】基于多物理场耦合的轻量化设计与可靠性分析:Python实现方案及关键技术解析(含详细代码及解释)