我正在嘗試使用angular和TypeScript創建SPA。我遇到了似乎是微不足道的問題,但幾個小時的互聯網服務沒有結果。使用Typescript的Ui路由器狀態定義
Application.ts
/// <reference path='_all.ts' />
module app {
'use strict';
angular.module('app.controllers',['ui.router'])
.config(['$stateProvider', function ($stateProvider) {
$stateProvider
.state('review', {
url: "/review",`enter code here`
templateUrl: "assets/html/review.html",
controller: 'ReviewCtrl'
})
.state('games', {
url: "/games",
templateUrl: "assets/html/games.html"//,
//controller: 'controllers.GamesCtrl'
})
.state('rewards', {
url: "/rewards",
templateUrl: "assets/html/rewards.html"//,
//controller: 'controllers.RewardsCtrl'
})
.state('profile', {
url: "/profile",
templateUrl: "assets/html/profile.html"//,
//controller: 'controllers.ProfileCtrl'
})
}])
.controller('ReviewCtrl', ReviewCtrl)
.controller('GamesCtrl', GamesCtrl)
.controller('RewardsCtrl', RewardsCtrl)
.controller('ProfileCtrl', ProfileCtrl)
}
ReviewCtrl.ts
module app {
'use strict';
export class ReviewCtrl {
public static $inject = ['$scope','$stateParams'];
constructor(private $scope,
private $stateParams)
{
console.log($stateParams);
}
}
}
UI視圖變化成功地工作,但添加控制器的狀態對象導致「〔毫微克:AREQ]參數 'ReviewCtrl' 是不是函數,得到了未定義的「異常。
試圖排除.js文件中的狀態,配置'app.controllers'模塊,但結果相同。
我有一個猜測,Typescript包裝控制器的東西,但我試過'app.controllers.ReviewCtrl','app.ReviewCtrl','controllers.ReviewCtrl',我仍然在這裏。
您使用的是什麼版本的TypeScript? – Brocco