angularjs-factory

AngularJS Modules and External Controllers

喜欢而已 提交于 2019-12-04 02:07:29
问题 I have a page containing multiple containers. Each container will have its own controller but point to one factory, which handles all the logic interacting with a web service API. I would like to have a separate file for each controller BUT I want all of this inside of one module. for the life of me I cannot find how to include controllers from different files into one modules. //file 1 MyController .... //file 2 MyOtherController //file 3 MyFactory //file 4 The Module The module would be

Can I have multiple functions in my AngularJS Factory?

做~自己de王妃 提交于 2019-12-03 18:59:38
问题 I'm following the Tutorial from the official AngularJS docs and I want to know if I can add another function to the Phone factory so that I can organize code better. They have declared a "query" function, but what if I wanted to add a query2 function that references a different url...say phones2/:phoneName.json for example? Factory declaration: var phonecatServices = angular.module('phonecatServices', ['ngResource']); phonecatServices.factory('Phone', ['$resource', function($resource){ return

Correct way to make a factory module in angularJs

老子叫甜甜 提交于 2019-12-02 17:19:58
问题 I have a controller function like this: $scope.localTimezone = function (userTimezone,datetime) { // .... return data; } What is the correct way to make it a factory module? I tried the following but it's giving errors. angular.module('localTimezone', []) .factory('localTimezone',function(userTimezone,datetime) { // ... return data; }); angular.module('app', ['localTimezone']) .controller('tasksController',function ($scope,localTimezone) { // ... }); I am missing out on some concept or logic

Correct way to make a factory module in angularJs

天涯浪子 提交于 2019-12-02 11:43:00
I have a controller function like this: $scope.localTimezone = function (userTimezone,datetime) { // .... return data; } What is the correct way to make it a factory module? I tried the following but it's giving errors. angular.module('localTimezone', []) .factory('localTimezone',function(userTimezone,datetime) { // ... return data; }); angular.module('app', ['localTimezone']) .controller('tasksController',function ($scope,localTimezone) { // ... }); I am missing out on some concept or logic.Can anyone please point me in the right direction? CONTROLLER Example Bad: function MainCtrl () { this

AngularJS Modules and External Controllers

走远了吗. 提交于 2019-12-01 13:27:28
I have a page containing multiple containers. Each container will have its own controller but point to one factory, which handles all the logic interacting with a web service API. I would like to have a separate file for each controller BUT I want all of this inside of one module. for the life of me I cannot find how to include controllers from different files into one modules. //file 1 MyController .... //file 2 MyOtherController //file 3 MyFactory //file 4 The Module The module would be composed of MyController, MyOtherController and MyFactory defined in three separate files. Can someone

AngularJS : returning data from service to controller

一世执手 提交于 2019-11-30 07:18:23
I am trying to create a service to get json and pass it to me homeCtrl I can get the data but when a pass it to my homeCtrl it always returns undefined. Im stuck. My Service: var myService = angular.module("xo").factory("myService", ['$http', function($http){ return{ getResponders: (function(response){ $http.get('myUrl').then(function(response){ console.log("coming from servicejs", response.data); }); })() }; return myService; } ]); My Home Controller: var homeCtrl = angular.module("xo").controller("homeCtrl", ["$rootScope", "$scope", "$http", "myService", function ($rootScope, $scope, $http,

Angular - TypeError: XX is not a function

為{幸葍}努か 提交于 2019-11-30 07:12:10
问题 Maybe I'm missing some kind of property, but I'm follow this project and I'm getting this error in my controller. TypeError: loginService.signin is not a function This is my controller.js angular.module('appcontrollers', []).controller('LoginController', ['$rootScope', '$scope', '$http', '$location', '$localStorage', 'loginService', function ($rootScope, $scope, $http, loginService) { $scope.signin = function() { console.log("username: " + $scope.username); console.log("pass: " + $scope

Can I have multiple functions in my AngularJS Factory?

ぃ、小莉子 提交于 2019-11-30 03:20:36
I'm following the Tutorial from the official AngularJS docs and I want to know if I can add another function to the Phone factory so that I can organize code better. They have declared a "query" function, but what if I wanted to add a query2 function that references a different url...say phones2/:phoneName.json for example? Factory declaration: var phonecatServices = angular.module('phonecatServices', ['ngResource']); phonecatServices.factory('Phone', ['$resource', function($resource){ return $resource('phones/:phoneId.json', {}, { query: {method:'GET', params:{phoneId:'phones'}, isArray:true}

How can I extend the constructor of an AngularJS resource ($resource)?

折月煮酒 提交于 2019-11-29 22:33:16
I have a model, defined using $resource , that I am successfully loading. Each loaded instance is, as promised, an instance of the class I defined. (The example below is from the Angular docs. In it, User.get results in an object that is an instanceof User .) var User = $resource('/user/:userId', {userId:'@id'}); However, imagine each User comes over the wire like this: { "username": "Bob", "preferences": [ { "id": 1, "title": "foo", "value": false } ] } I defined a Preference factory that adds valuable methods to Preference objects. But when a User loads, those preferences aren’t Preference s

Angular - TypeError: XX is not a function

走远了吗. 提交于 2019-11-29 02:00:00
Maybe I'm missing some kind of property, but I'm follow this project and I'm getting this error in my controller. TypeError: loginService.signin is not a function This is my controller.js angular.module('appcontrollers', []).controller('LoginController', ['$rootScope', '$scope', '$http', '$location', '$localStorage', 'loginService', function ($rootScope, $scope, $http, loginService) { $scope.signin = function() { console.log("username: " + $scope.username); console.log("pass: " + $scope.password); var formData = { username: $scope.username, password: $scope.password }; // ERROR IN THIS LINE