में सेवा का उपयोग करें मुझे कोणीय जेएस सेवा के साथ समस्या है।देखें कोणीय जेएस
angular.module('mainApp.services', []).factory('AuthService',
function ($http) {
//var currentUser = null;
//var authorized = false;
//AutoLogin for testing
var currentUser={email: "[email protected]", id: "15"};
var authorized=true;
// initial state says we haven't logged in or out yet...
// this tells us we are in public browsing
var initialState = false;
return {
initialState:function() {
return initialState;
},
login:function (userData) {
//Call API Login
currentUser = userData;
authorized = true;
initialState = false;
},
logout:function() {
currentUser = null;
authorized = false;
},
isLoggedIn:function() {
return authorized;
},
currentUser:function() {
return currentUser;
},
authorized:function() {
return authorized;
}
};
});
तो मैं एक साधारण नियंत्रक
.controller('NavbarTopCtrl', ['$scope','$modal','AuthService',function($scope,$modal,authService) {
$scope.authService=authService; //IS good practice?
console.log($scope);
}])
मैं दृश्य में मेरी सेवा का उपयोग नहीं कर सकते हैं:
मैं साधारण सेवा है। मैंने सरल चाल बनाई और ठीक काम करता है।
$scope.authService=authService
लेकिन यह कैसे मेरी देखें (HTML फ़ाइल) में इस के बिना सेवा कॉल करने के लिए?
सेवा लॉगिन करने के लिए यहां देखें। यह बढ़िया काम करता है। https://github.com/robertjchristian/angular-enterprise-seed –
आपके पास फ़ंक्शंस का एक सेट कब है, जिसे आप दृश्य से कॉल करने योग्य चाहते हैं जैसे 'ng-click'? कंट्रोलर के अंदर कॉलर फ़ंक्शन के अंदर दृश्य में आने वाले प्रत्येक एकल फ़ंक्शन को लपेटना बहुत कठिन है। विचार? –
myApp.configure (फ़ंक्शन ($ rootScope) {$ rootScope.foo = function() {console.log ("मुझे हर जगह से कॉल करें;)")}; – luacassus