I will soon start to eat my jacket, but I will not go home until I find the reason. Started as usual with the controller, then the second. Added ngRoute, it took to write the factory and started. The FormsListCtrl controller works as expected, the list from the database is delivered and displayed on the page, while the console gets undefined. But with the controller EditorCtrl miracles happen. The factory should return, from the previously received list of forms, the form specified by the ID. It seems that it fulfills and returns what was required. Where to find it? Such things are seen in the console, but nothing gets into the markup. Tell me please, where to look?

And from the factory log is displayed last. Why does the first controller display on the page, and the second (written by analogy) no?

PS Everything is written in the HTML code as it should be.

AP: the page does not get, because instead of an object from the database comes a string, but not in the console, because the factory works after.

Angulyar console

<!DOCTYPE html> <html lang="ru" ng-app="formEditor"> <head> <title>TODO supply a title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="/css/style.css" /> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js?456"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-route.min.js"></script> <script src="js/jquery-1.12.0.min.js"></script> <script src="js/script.js"></script> </head> <body> <div ng-view></div> </body> </html> var formEditor = angular.module('formEditor', ['ngRoute']); formEditor.config(function($routeProvider){ $routeProvider. when('/',{ template:'<span ng-repeat="form in forms"><a href="#/{{form.id}}">{{form.name}}</a> </span>', controller:'FormsListCtrl' }). when('/:formIdi',{ template:'<span ng-bind="set.b.brdr.style"></span><span ng-bind="set.c"></span><span ng-bind="set.d"></span>', controller:'EditorCtrl' }). when('/:formId',{ templateUrl:'/view/view_editor.html', controller:'EditorCtrl2' }). otherwise({redirectTo:'/'}); }); // получаем список форм formEditor.factory('formsFctr', function($http){ function getData(callback){ $http({ method:'GET', url:'/ajax/action.php?action=form&sub=list', cache:true }).success(callback); } return{ list:getData, find: function(param, callback){ getData(function(data){ var form = data.filter(function(entry){ return entry.id === param; })[0]; callback(form); }); } }; }); formEditor.controller('FormsListCtrl', ['$scope', 'formsFctr', function($scope, formsFctr){ formsFctr.list(function(forms){ $scope.forms = forms; }); console.log($scope.forms); }]); formEditor.controller('EditorCtrl', ['$scope', '$routeParams', 'formsFctr', function($scope, $routeParams, formsFctr){ formsFctr.find($routeParams.formIdi, function(form){ $scope.set = form.json; console.log($scope.set); }); $scope.set = {b:{brdr:{style:"solid"}},c:"cycle",d:$routeParams.formIdi}; console.log($scope.set); console.log($scope); // обработка переключателя H/V $scope.reModes = function(){ if($scope.set.modes.done === 'horizontal'){ $scope.set.b.width = 372; } if($scope.set.modes.done === 'vertical'){ $scope.set.b.width = 180; } }; }]); 
  • well, that's why nothing is output that $scope.set is a string and it has no fields to which you refer in the template - Grundy

0