app.js

'use strict' var app = angular.module('app', ['ui.router']) .constant('host', 'http://raport.local/public/') .factory('raports', ['$http', 'host', function ($http, host) { var raports = {}; raports.getRaport = function (raportID) { return $http.get(host + 'raport/' + raportID); }; return raports; }]) .config(["$stateProvider", function ($stateProvider) { $stateProvider .state("raport", { url:"/raport/{raportID}", templateUrl: "tpl/raport.html", resolve: { raporter: function ($stateParams,raports) { return raports.getRaport($stateParams.raportID) .$promise.then( function(data) { return data; }, function(error) { return error; }); } }, controller: "raportich" }) }]) .controller('raportich', ['raports','raporter', function (raports,raporter) { this.raportichca= raporter; //raports.getRaport(4); }]); index.html 
 <!DOCTYPE html> <html lang="en" ng-app="app"> <head> <meta charset="UTF-8"> <title>Title</title> <link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.css"> <script src="node_modules/angular/angular.js"></script> <script src="node_modules/angular-ui-router/release/angular-ui-router.js"></script> <script src="app.js"></script> </head> <body > <a ui-sref="raport({raportID:4})">Ссылка</a> <ui-view></ui-view> </body> </html> 

Now, after loading the page, the template from templateUrl is not connected, but the function passes from resolve, and removing the resolve, the template is loaded. What could be the problem?

  • Perhaps because you have an error in the raporter function. Try rewriting the raporter: function ($stateParams,raports) { return raports.getRaport($stateParams.raportID).then( function(data) { return data; }, function(error) { return error; }); } like raporter: function ($stateParams,raports) { return raports.getRaport($stateParams.raportID).then( function(data) { return data; }, function(error) { return error; }); } raporter: function ($stateParams,raports) { return raports.getRaport($stateParams.raportID).then( function(data) { return data; }, function(error) { return error; }); } - Stepan Kasyanenko Nov.

0