我目前正在管理一个AngularJS开发项目.有人说我们需要从目前的1.2中至少迁移到AngularJS 1.5.我要求移动的一个要求是我必须提供1.5的支持结束的证据,但在角度站点和多个谷歌搜索后数小时后找不到支持信息的任何结尾.
是否有关于何时不再为Angular v1.x开发安全补丁和错误修复的官方评论?
我有以下代码:
angular
.module('myApp')
.directive('layout', function () {
return {
restrict: 'E',
template: '<div ng-include="layoutCtrl.pageLayout"></div>',
controller: 'LayoutController',
controllerAs: 'layoutCtrl',
bindToController: true,
scope: {
pageLayout: '=',
pageConfiguration: '=',
isPreview: '='
}
};
});
angular
.module('myApp')
.controller('LayoutController', LayoutController);
function LayoutController($scope, LayoutDTO, LayoutPreviewDTO) {
var self = this;
self.layoutDTO = LayoutDTO;
self.layoutPreviewDTO = LayoutPreviewDTO;
var test = $scope;
if(self.isPreview)
self.layoutModel = new self.layoutPreviewDTO(self.pageConfiguration);
else
self.layoutModel = new self.layoutDTO(self.pageConfiguration);
}
<div>
<layout page-layout="ctrl.layoutTemplateUrl" page-configuration="ctrl.pageConfiguration" is-preview="false"></layout>
</div>
Run Code Online (Sandbox Code Playgroud)
在角度1.5.3版本中,这按预期工作,我的控制器中的变量带有值.现在,自从我升级到1.6.x后,self.pageConfiguration现在未定义.
除角度版本外,没有任何改变.
如何处理传递给控制器中指令的值?
angularjs angular-directive angular-controller angularjs-1.6
从AngularJs 1.5升级到1.6状态时,$ compile中的更改的文档:
默认情况下禁用对组件/指令控制器实例的预分配绑定,这意味着它们将不再在构造函数内可用.
文档中的升级示例如下(缩写):
之前
.component('myComponent', {
bindings: {value: '<'},
controller: function() {
//...
}
})
Run Code Online (Sandbox Code Playgroud)
后
.component('myComponent', {
bindings: {value: '<'},
controller: function() {
this.$onInit = function() {
// ...
};
}
})
Run Code Online (Sandbox Code Playgroud)
我已经发现我必须使用相同的$ onInit函数为任何使用bindToController的指令:true就像这里:
.directive('acAllocation', acAllocation);
function acAllocation(SomeService) {
return {
restrict: 'E',
replace: true,
scope: {
allocation: '=acAllocation'
},
controller: acAllocationController,
controllerAs: 'vm',
bindToController: true,
templateUrl: 'path/acAllocation.html'
};
function acAllocationController() { …Run Code Online (Sandbox Code Playgroud) angularjs angularjs-directive angularjs-components angularjs-1.6
尝试gulp serve在我的 AngularJS(1.6.10 版)应用程序上执行操作时收到以下错误消息:
Error: [$injector:modulerr] Failed to instantiate module myAppName due to:
$compileProvider.preAssignBindingsEnabled is not a function
@http://localhost:9805/app/scripts/app.js:43:9
invoke@http://localhost:9805/lib/angular/angular.js:5108:16
runInvokeQueue@http://localhost:9805/lib/angular/angular.js:4997:11
loadModules/<@http://localhost:9805/lib/angular/angular.js:5007:11
forEach@http://localhost:9805/lib/angular/angular.js:387:11
loadModules@http://localhost:9805/lib/angular/angular.js:4987:5
createInjector@http://localhost:9805/lib/angular/angular.js:4904:19
doBootstrap@http://localhost:9805/lib/angular/angular.js:1936:20
bootstrap@http://localhost:9805/lib/angular/angular.js:1957:12
angularInit@http://localhost:9805/lib/angular/angular.js:1842:5
@http://localhost:9805/lib/angular/angular.js:35431:5
mightThrow@http://localhost:9805/lib/jquery/dist/jquery.js:3534:21
Run Code Online (Sandbox Code Playgroud)
调用代码如下所示:
/*
* Main module of the application.
*/
angular
.module('dataPipelineApp', [
//various parameters
])
.config(['$compileProvider', '$httpProvider', '$breadcrumbProvider', function ($compileProvider, $httpProvider, $breadcrumbProvider) {
//initialize get if not there
if (!$httpProvider.defaults.headers.get) {
$httpProvider.defaults.headers.get = {};
}
$compileProvider.preAssignBindingsEnabled(true); //err here
$httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
// extra …Run Code Online (Sandbox Code Playgroud)