2014-02-09 6 views
1

Люди, у меня возникла проблема с привязкой данных. Я пытался с возрастом выяснить, почему у моих немногих нет доступа к моему global.user, предоставленному службой. Может кто-нибудь выяснить, что происходит. Заранее спасибо. С наилучшими пожеланиями Томаспроблемы с привязкой данных с angularjs

profile.html

<section data-ng-controller="MyprofileController"> 
<h1>{{global.current_User()}}</h1> 
</section> 

myprofile.js

'use strict'; 

angular.module('mean.system').controller('MyprofileController', ['$scope', 'Global',   function ($scope, Global) { 
$scope.global = Global; 
$scope.test = 'testcase';}]); 

сервис

'use strict'; 

//Global service for global variables 
angular.module('mean.system').factory('Global', [ 
function() { 
    var current_user = window.user; 
    return { 
     current_User: function() { 
      return current_user; 
     }, 
     isloggedIn: function() { 
      return !!current_user; 
     } 
    }; 
} 

]);

благодарит за вашу помощь.

Только что выяснили, что firefox выводит сообщение об ошибке!

Error: [ng:areq] Argument 'MyprofileController' is not a function, got undefined 
http://errors.angularjs.org/1.2.11/ng/areq? 
p0=MyprofileController&p1=not%20a%20function%2C%20got%20undefined 
minErr/<@http://localhost:3000/lib/angular/angular.js:78 
[email protected]://localhost:3000/lib/angular/angular.js:1363 
[email protected]://localhost:3000/lib/angular/angular.js:1374 
@http://localhost:3000/lib/angular/angular.js:6774 
nodeLinkFn/<@http://localhost:3000/lib/angular/angular.js:6186 
[email protected]://localhost:3000/lib/angular/angular.js:310 
[email protected]://localhost:3000/lib/angular/angular.js:6173 
[email protected]://localhost:3000/lib/angular/angular.js:5637 
[email protected]://localhost:3000/lib/angular/angular.js:5542 
ngViewFillContentFactory/<[email protected]://localhost:3000/lib/angular-route/angular-  
route.js:915 
[email protected]://localhost:3000/lib/angular/angular.js:6228 
[email protected]://localhost:3000/lib/angular/angular.js:5637 
[email protected]://localhost:3000/lib/angular/angular.js:5542 
[email protected]://localhost:3000/lib/angular/angular.js:5656 
controllers[email protected]://localhost:3000/lib/angular/angular.js:6248 
[email protected]://localhost:3000/lib/angular-route/angular-route.js:865 
[email protected]://localhost:3000/lib/angular/angular.js:12245 
updateRoute/<@http://localhost:3000/lib/angular-route/angular-route.js:556 
qFactory/defer/deferred.promise.then/[email protected]: 
//localhost:3000/lib/angular/angu  lar.js:10949 
qFactory/defer/deferred.promise.then/[email protected]: 
//localhost:3000/lib/angular/angu  lar.js:10949 
qFactory/ref/<.then/<@http://localhost:3000/lib/angular/angular.js:11035 
[email protected]://localhost:3000/lib/angular/angular.js:11961 
[email protected]://localhost:3000/lib/angular/angular.js:11787 
[email protected]://localhost:3000/lib/angular/angular.js:12067 
@http://localhost:3000/lib/angular/angular.js:9202 
createEventHandler/eventHandler/<@http://localhost:3000/lib/angular/angular.js:2613 
[email protected]://localhost:3000/lib/angular/angular.js:310 
createEventHandler/[email protected]://localhost:3000/lib/angular/angular.js:2612 

<section class="ng-scope" data-ng-view=""> 

ответ

0

Он должен работать, и это делает в Fiddle я создал: http://jsfiddle.net/BernhardW/mLQWs/

window.user = 'John Doe'; 

angular.module('mean.system', []); 

angular.module('mean.system').controller('MyprofileController', function ($scope, Global) { 
    $scope.global = Global; 
    $scope.test = 'testcase'; 
}); 

angular.module('mean.system').factory('Global', function() { 
    var current_user = window.user; 

    return { 
     current_User: function() { 
      return current_user; 
     }, 
     isloggedIn: function() { 
      return !!current_user; 
     } 
    }; 
}); 

Существует ли какая-либо ошибка, показывающая?

+0

Нет, это не то, что я не получаю никаких ошибок! просто доцентная работа. Я начинаю со средним.io как шаблон. – user3289757

+0

Вы можете воссоздать упрощенный пример (только с необходимым кодом) на http://jsfiddle.net/ или http://plnkr.co/, и я посмотрю. Ошибка, кажется, вне кода отправлена, потому что, когда я копирую и вставляю ваш код выше, все работает. – bernhardw

+0

Я только что узнал, что firefox выводит сообщение об ошибке! Помогает ли это? – user3289757

Смежные вопросы