Tag: angularjs factory

AngularJS – 工厂未定义?

我试图将一个工厂注入控制器。 工厂是为了pipe理authentication事件。 这是一些代码: 'use strict'; /** * @ngdoc function * @name LoginCtrl * @module triAngularAuthentication * @kind function * * @description * * Handles login form submission and response */ angular.module('triAngularAuthentication') .factory('Auth', ['$http', 'localStorageService', function ($http, localStorageService, API_REST) { function urlBase64Decode(str) { var output = str.replace('-', '+').replace('_', '/'); switch (output.length % 4) { case 0: […]

发送$ http.get两次

编辑1:伙计们,我注意到我在我的authentication工厂调用$ http.get('/ posts')(用于某些特殊用途)。 对不起,这个愚蠢的问题。 当赏金结束时我会删除它。 我有以下代码来加载页面https://localhost:3000/#/home ,它从数据库中获取所有post并显示它们。 问题是,我意识到日志router.get /posts是打印两次,而here和there只提醒一次。 有谁知道这是否意味着$http.get被执行两次? 如果是的话,问题在哪里? app.config(… …) { $stateProvider .state('global', { templateUrl: '/htmls/global.html', controller: 'GlobalCtrl' }) .state('global.home', { url: '/home', templateUrl: '/htmls/home.html', controller: 'MainCtrl', resolve: { postPromise: ['posts', function (posts) { return posts.getAll(); }] } }); }]); app.factory('posts', ['$http', 'auth', function ($http, auth) { var o = { posts: […]