angular-ui-路由器跟踪控制器分配
angular-ui-router traceur controller assignation
我正在尝试将控制器分配给 ui-路由器中的状态。 controller是traceur编译的
状态分配如下所示:
$stateProvider
.state('form', {
url: '/form'
, templateUrl: 'views/form.html'
, controller: 'FormController as Form'
})
编译后的控制器如下所示:
var FormController = function FormController($stateParams, $http) {
this.data = {};
this._stateParams = $stateParams;
this._http = $http;
this.formTemplate = "";
};
($traceurRuntime.createClass)(FormController, {
submit: function() {
console.log('submitted');
}
}, {});
我显然收到一个运行时错误,提示 FormController 不是一个函数。有办法解决吗?还有其他解决方案吗?
有working example - 我只是改变了定义的顺序
var app = angular.module('brokenApp', ['ui.router'])
.config(ApplicationConfig)
;
// controller def in JS world
var FormController = function ($sc, $stateParams, $http) {
$sc.title = "hello from scope";
this.title = "hello from controller";
this.data = {};
this._stateParams = $stateParams;
this._http = $http;
this.formTemplate = "";
};
// DI
FormController.$inject = ['$scope', '$stateParams', '$http']
// controller injection into angular
app.controller('FormController', FormController);
有新的form.html
<h1>Hello Plunker!</h1>
<h3>$scope.title: </h3>
{{title}}
<h3>controller.title: </h3>
{{Form.title}}
而不是这个original code:
angular.module('brokenApp', ['ui.router'])
.config(ApplicationConfig)
.controller('FormController', FormController);
//# sourceURL=app-wrapper.js
"use strict";
var FormController = function FormController($stateParams, $http) {
this.data = {};
this._stateParams = $stateParams;
this._http = $http;
this.formTemplate = "";
};
检查工作版本here
我正在尝试将控制器分配给 ui-路由器中的状态。 controller是traceur编译的
状态分配如下所示:
$stateProvider
.state('form', {
url: '/form'
, templateUrl: 'views/form.html'
, controller: 'FormController as Form'
})
编译后的控制器如下所示:
var FormController = function FormController($stateParams, $http) {
this.data = {};
this._stateParams = $stateParams;
this._http = $http;
this.formTemplate = "";
};
($traceurRuntime.createClass)(FormController, {
submit: function() {
console.log('submitted');
}
}, {});
我显然收到一个运行时错误,提示 FormController 不是一个函数。有办法解决吗?还有其他解决方案吗?
有working example - 我只是改变了定义的顺序
var app = angular.module('brokenApp', ['ui.router'])
.config(ApplicationConfig)
;
// controller def in JS world
var FormController = function ($sc, $stateParams, $http) {
$sc.title = "hello from scope";
this.title = "hello from controller";
this.data = {};
this._stateParams = $stateParams;
this._http = $http;
this.formTemplate = "";
};
// DI
FormController.$inject = ['$scope', '$stateParams', '$http']
// controller injection into angular
app.controller('FormController', FormController);
有新的form.html
<h1>Hello Plunker!</h1>
<h3>$scope.title: </h3>
{{title}}
<h3>controller.title: </h3>
{{Form.title}}
而不是这个original code:
angular.module('brokenApp', ['ui.router'])
.config(ApplicationConfig)
.controller('FormController', FormController);
//# sourceURL=app-wrapper.js
"use strict";
var FormController = function FormController($stateParams, $http) {
this.data = {};
this._stateParams = $stateParams;
this._http = $http;
this.formTemplate = "";
};
检查工作版本here