angularjs-scope

AngularJS: two promises from one $http call

三世轮回 提交于 2019-12-25 05:30:34
问题 I wonder what is the most elegant way to initialize/the objects that I fill from the AJAX call and are used 'concurrently' somewhere in a directive. I have a controller with such snippet: $scope.var1 = {}; $scope.var2 = {}; $http({ url: "/httpService", method: "GET", params: {} }).success(function(data, status) { $scope.var1 = data.some; // (*1) $scope.var2 = data.other; }) I am also using a directive which binds directly to var1: var1 : '=' and inside the directive there is some check on

How to communicate between controllers while not using SharedService between them?

跟風遠走 提交于 2019-12-25 03:55:35
问题 I was reading all the answers about communication between controllers and directive, but is seems to me occurred using shared service and inject it to each one of them. When I'm developing a very large scale application, I don't know what my page is going to have in it. I may have 2 controllers need to communicate between them, and I also may have 5 directive and 2 controllers in the same page. I don't know from scratch what is going to be inside my view/page, so I need a better way how to

How to communicate between controllers while not using SharedService between them?

微笑、不失礼 提交于 2019-12-25 03:55:03
问题 I was reading all the answers about communication between controllers and directive, but is seems to me occurred using shared service and inject it to each one of them. When I'm developing a very large scale application, I don't know what my page is going to have in it. I may have 2 controllers need to communicate between them, and I also may have 5 directive and 2 controllers in the same page. I don't know from scratch what is going to be inside my view/page, so I need a better way how to

AngularJS get data from json

为君一笑 提交于 2019-12-25 03:47:17
问题 I'm trying to get from Json data but it doesn't worked for me. I'm not sure what I'm doing wrong. Angular Ajax API call : <script> function PostsCtrlAjax($scope, $http) { $http({ method: 'POST', url: 'js/posts.json' }).success(function(data) { $scope.posts = data.deals;; // response data }); } </script> HTML Data Binding <div id="ng-app" ng-app ng-controller="PostsCtrlAjax"> <div ng-repeat="post in posts"> <h2> <a href='{{post.url}}'>{{post.title}}</a> </h2> <div class='time'>{{post.time}} -

asynchronous callback returns null

感情迁移 提交于 2019-12-25 03:25:01
问题 I am trying to assign callback function values and display ng-repeat var myApp = angular.module('mybet',[]); myApp.controller('MyBetController', function($scope,$firebase,ProfileFactory,MybetFactory){ $scope.myBetEvents = MybetFactory.getUsersBetsProfile(currentLoggedUser, function(betsData){ //Callback retuning null value here $scope.myBetEvents = betsData; }); }); myApp.factory('MybetFactory', ['$firebase', function($firebase){ var factory = {}; factory.getUsersBetsProfile = function(userId

AngularJS ng-click toggling between functions

一个人想着一个人 提交于 2019-12-25 03:19:16
问题 <span ng-click="resetbyTask() || filterTask(task.id, $index)">{{ task.total }}</span> I am trying to toggle between fucntions in a single ng-click so that the first click will run filterTask() and when clicked again it will run resetbyTask 回答1: Try this : // controller var called = false; $scope.toggle = function (taskId, index) { if (called) { called = false; return $scope.resetbyTask(); } $scope.filterTask(taskId, index); called = true; } HTML : <span ng-click="toggle(task.id, $index)">{{

AngularJS filter search not working at all

隐身守侯 提交于 2019-12-25 03:00:31
问题 I am writing an app using AngularJS on the front end. I want to search through a table by any word/field; one search box for everything. I tried to follow this plunker's working example: http://plnkr.co/edit/aIuSDYlFbC4doW6pfsC9?p=preview This is my code on the front end: <div class = "row"> <label>Search: <input ng-model="query"></label> </div> <div class = "row"> <table ng-repeat="post in posts | orderBy: sort | filter: search"> <tr> <td> {{index(post)}} </td> <td> {{post.title}} </td> <td>

How to select Parent Checkbox when a Child is selected inside ng-repeat

一世执手 提交于 2019-12-25 02:57:50
问题 I am having a very hard time trying to figure out a solution for this. I have a checkbox group where the first checkbox is the parent and the following in that set will be child. I want the parent checkbox to be selected automatically if one of the child's checkbox is selected. Similarly parent needs to be get unchecked if no child is selected. Here is my jsfiddle example: http://jsfiddle.net/Alien_time/PqTR7/3/ The main difficulty I am facing is because the checkboxes are created dynamically

How to access $rootScope value defined in one module into another module

妖精的绣舞 提交于 2019-12-25 02:54:01
问题 I need to understand " How can I access the value of $rootScope value defined in one module into other module? " Below is my code : Index.html <!DOCTYPE html> <html ng-app="myapp"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"> </script> <link rel="stylesheet" href="style.css"> <script src="script.js"></script> <script src="test.js"></script> </head> <div ng-controller="serviceDIController"> Service Values is : <b> {{sdiParam}} </b> <br/> Factory

Pass a input field value into angularjs $resource undefined and error shows unknown scope provider

半城伤御伤魂 提交于 2019-12-25 02:38:28
问题 =========================================================================== Update 1 Fixed code produce new error of ReferenceError: inputName is not defined on the line of inputName:inputName, Below is the new code <script src="/library/angularjs/1.2.0-rc.3/angularjs.js"></script> <script src="/library/angularjs/1.2.0-rc.3/angular-route.js"></script> <script src="/library/angularjs/1.2.0-rc.3/angular-resource.js"></script> <script> var app= angular.module('myApp', ['ngRoute', 'ngResource']);