当我运行这样的代码时,我的控制器停止工作,它发生在从api或任何其他方式传递的所有类型的数据...我只是不能将任何东西传递给我的控制器
> $urlRouterProvider.otherwise('/movies')
> $stateProvider
> .state('movies', {
> url: '/movies',
> templateUrl: 'templates/movies.html',
> controller: 'indexCtrl',
> resolve: {
> resolveParam: function(){
> return 'sdsadasdasd'
> }
> }
> })
>
> }]);
>
>
> app.controller('indexCtrl', ['$scope', 'resolveParam', function($scope, resolveParam) {
> $scope.click = function() {
> alert();
>
>
>
> }
> }]);
只要我像这样运行它,它就可以完美地运行
app.controller('indexCtrl', ['$scope', function($scope) {
$scope.click = function() {
alert();
}
}]);
即使我的州仍然像上面那样......
答案 0 :(得分:0)
您可能有拼写错误或其他一些难以追踪的错误。 基于你的代码的JSfiddle运行得很好。
JS
angular.module('app', ['ui.router'])
.config(['$urlRouterProvider', '$stateProvider', function($urlRouterProvider, $stateProvider) {
$urlRouterProvider.otherwise('/movies')
$stateProvider
.state('movies', {
url: '/movies',
template: '<div>{{resolveParam}}</div>',
controller: 'indexCtrl',
resolve: {
resolveParam: function() {
return 'sdsadasdasd';
}
}
})
}])
.controller('indexCtrl', ['$scope', 'resolveParam', function indexCtrl($scope, resolveParam) {
$scope.resolveParam = resolveParam;
}]);
HTML
<html>
<head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.9/angular.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.3.2/angular-ui-router.js"></script>
</head>
<body ng-app="app" class="ng-scope">
<ui-view></ui-view>
</body>
</html>
输出