Tagged Questions
26
votes
3answers
31k views
How do I use $rootScope in Angular to store variables?
How do I use $rootScope to store variables in a controller I want to later access in another controller? For example:
angular.module('myApp').controller('myCtrl', function($scope) {
var a = ...
6
votes
1answer
3k views
Sharing data between AngularJS controllers? [duplicate]
How do I store the items I've selected in a checkbox with other controllers?
My attempt (see the plnkr for views):
script.js (controllers)
var myApp = angular.module('myApp', []);
...
5
votes
3answers
1k views
How to create a two-way data binding between two isolated controllers and a shared service in AngularJS?
I am trying to create a two-way data binding between two isolated controllers and a shared service (which provides another isolated scope):
app.factory("sharedScope", function($rootScope) {
var ...
3
votes
2answers
4k views
AngularJS: open a new browser window, yet still retain scope and controller, and services
I'm writing an angularJS app. In this particular controller, I open a new browser window through the $window.open service. But in the new window, all the $scope variables are lost.
I tried to use ...
3
votes
1answer
3k views
AngularJS The scope for dynamic content through $compile isn't attached to the controller scope
When I generate a new element through a string that has a directive (that's why I need to compile) and that directive generates an association with a variable in the controller scope through "=", the ...
3
votes
1answer
104 views
How do I resolve and assign an inner controller from the outer's scope?
Self explanatory fiddle: http://jsfiddle.net/5FG2n/1/
Say I have a view with two controllers, one containing the other. The outer controller is static, but I need to set the inner controller based ...
3
votes
1answer
522 views
Nested directives - cannot pass args to controller method from child directive in Angularjs
I'm having some trouble with nested directives in angularjs. I want to call a controller method from a directive within another directive and am trying to pass arguments to it, however they are ...
2
votes
3answers
658 views
How do I access the $scope variable of one controller from another in Angular.js?
I have this:
app.controller('foo1', function ($scope) {
$scope.bar = 'foo';
});
app.controller('foo2', function ($scope) {
// want to access the $scope of foo1 here, to access bar
});
How would ...
2
votes
2answers
381 views
Evaluating expression in ng-controller
My Javascript
var app = angular.module('Demo', []);
app.controller('DemoCtrl', function ($scope) {
$scope.expr = "Test"
});
app.controller('Test', function ($scope) {
$scope.HELLO = "HEllo ...
2
votes
2answers
148 views
Did I share state correctly outside angular directive? (parent scope / $rootScope issue)
I have two elements on my page which are not nested in some way. With attributes on the first one, I would like to set the content of the second one, like so:
<body>
<input info="This is ...
2
votes
1answer
2k views
How to access the $ngModelController from inside the Controller without a Form and without a Directive
Maybe it's a rookie mistake, but I can't seem to access the $scope.model's $ngModelController so I can grab the $viewValue from it.
I have an input without a form (im using ui-mask directive):
...
2
votes
1answer
134 views
Angular binding model in scope issue?
Hi I am new to the angular js and trying to write the chat application using the socket io and angular js with ionic for android platform. But in my chat page there is one issue.
I am trying to bind ...
2
votes
0answers
121 views
Angular directive in ng-repeat doesn't call link
I'm fairly new to Angular and am having some trouble getting a directive to render within an ng-repeat. This is probably a lack of experience on my part so any help is greatly appreciated.
Here are ...
1
vote
1answer
77 views
Customize AngularJS Bootstrap Tooltip
How do I add custom placements/animations to an AngularJS/Bootstrap tooltip? I can do:
myApp.controller('TooltipCtrl', function ($scope) {
$scope.htmlTooltip = 'Here is a tooltip!';
});
And it ...
1
vote
1answer
2k views
Reinitialize an Angular.js controller
if you have a controller to manipulate $scope variables in Angular.js, is there an idiomatic way to:
reset the controller's $scope, and
restart controller initialization?
For complex controllers ...
1
vote
1answer
443 views
AngularJS sharing data between factory & controller across modules
I have an angularjs app that has several modules. The main modules looks something like:
var app = angular.module('mainMod', ['apiService']);
app.controller('MainCtrl', function (Socket) {
...
1
vote
2answers
754 views
From an AngularJS controller, how do I resolve another controller function defined in the module?
Self explanatory fiddle: http://jsfiddle.net/5FG2n/6/
I need to dynamically choose the controller to use at runtime based on its name as a string. The string will be read from a config object.
In ...
1
vote
1answer
22 views
Trouble getting size of an array in a js object inside controller
I want to get the size of some data I am retrieving in my controller - I have tried the following code; both utilizing a new Object.size function and attempted to get the length property directly ...
1
vote
3answers
97 views
Best practice for defining scope variables
I have this form. This form contains many many inputs like first name, last name, job title, notes, state, department, documents, supervisor...and so on
Originally I had a controller like so
...
1
vote
2answers
33 views
Altering $scope controller variables on URL
I have a simple web app that is just a table with formatted JSON data. When you click on a column, you can filter that column in ascending order.
I would like for actions like that to change the url ...
1
vote
1answer
59 views
Getting variable from socket.io in AngularJS
Basically i have two sources of data, one is real time data from socket.io and other is json object. And i'm using both in front-end but the problem is that i need to pass a variable from socket.io to ...
1
vote
1answer
32 views
How to store/communicate global asynchronous data to controllers
The basic premise is this....
I have an application. When the user hits the application, it immediately fetches various information regarding the user from a sharepoint server through an ajax call. ...
1
vote
2answers
70 views
In an AngularJs directive, how do I call its controller's function contained within an directive element's attribute?
I am trying to call a function in a controller, which is part of a custom angular directive, following is the code,
Method 1: (Doesn't work: Controller's function doesn't write to the console)
HTML:
...
1
vote
1answer
104 views
Is $routeChangeSuccess guarantied to be fired inside a newly instantiated controller?
Suppose we have an /example route and the ExampleCtrl associated:
.when('/example', {
templateUrl : 'example.html',
controller: 'ExampleCtrl'
})
&
ExampleCtrl = function(){
...
1
vote
2answers
4k views
AngularJS - refresh view after http request, $rootScope.apply returns $digest already in progress
Hey guys so I am simply trying to load data when my app starts. However, the view loads faster than the http request(of course). I want to refresh my view once my data has been properly loaded because ...
1
vote
2answers
1k views
ng-repeat not updating using $scope.$watch
I need some help in displaying the results of an update in my ng-repeat directive from $watch
ProductsCtrl is watching for a change of product type and when it detects one it searches for Products ...
1
vote
1answer
107 views
Service vs Inheritance for Access Parameters Outside `ng-view`
Is it more effective to use a Service or rely on Scope Inheritance when updating parameters outside an AngularJS ng-view?
I have an AngularJS page with an ng-view and a common header. When moving ...
1
vote
1answer
32 views
Angular not scoped method
I am wondering, does all the methods declared in an angular controller have to be added to the scope?
is it possible to call a controller method from ng-click="myMethod()", with my method not delared ...
0
votes
2answers
33 views
AngularJS load in controllers that are in separate files
app.config(function($routeProvider) {
$routeProvider
// route for the home page
.when('/demo', {
templateUrl : 'assets/pages/home.html'
})
...
0
votes
3answers
69 views
AngularJS Won't Recognize Multiple Controllers in Single HTML File
I'm finding a weird instance where I am trying to use multiple AngularJS controllers on a single HTML page, and the page will either a, recognize only one of the controllers, or b, recognize none of ...
0
votes
3answers
3k views
$watch not working on variable from other controller?
I have one controller which displays a checklist, and stores the selection in an array.
My other controller runs an $http.get on the array from the first controller.
How do I set a $watch so that ...
0
votes
2answers
47 views
In Angular, how to make sure that $broadcast listener is loaded when a message is broadcast
I have two controllers in my Angular app. When a certain piece of data updates in one, it sends out a $broadcast event, like so:
$scope.updateTableInfo = function (table) {
...
0
votes
2answers
75 views
Directive talks to controller but cannot call functions residing in controller
I have a directive which needs to call functions from the Main controller but everytime i try to reference a function inside the directive nothing happens because it's undefined. When I access a value ...
0
votes
2answers
49 views
$watch's object not triggered when attributes are changed
I have one object:
$scope.obj = {bar: 'bar value', foo: 'foo value'};
and I want to to know if bar, foo or both change.
I'm doing this:
$scope.$watch('obj', function() { console.log("watching ...
0
votes
2answers
29 views
Angular $scope set to another $scope value not working
I am trying to give one $scope variable the value of another $scope variable. Can someone tell me what is going wrong? Take a look at the simple plunker for details:
...
0
votes
1answer
290 views
AngularJS - mechanics of $scope.$watch - is it just an observer pattern?
I have some factory:
.factory("someFactory", function() {
var someFactory = {};
someFactory.objects = [
{ name: "obj1" },
{ name: "obj2" }
];
return someFactory;
}
And some ...
0
votes
1answer
88 views
How do I properly set a service property from model data in a controller in angularjs?
I've set up a service to share some data/state between multiple controllers. In one controller, I update some of the service properties with scope data through a save function. That data is then used ...
0
votes
1answer
759 views
Trigger the $scope.submit() event of blueimp in angular programmatically
When I use the submit() event of blueimp file uploader within the DOM, everything seems to work fine. i.e.:
<span class="btn" ng-click="submit()">Go</span>
However, calling ...
0
votes
1answer
1k views
Angular: call service once multiple controllers
This should be a fairly straight forward question, but I'm stumped.
I have a service that makes an http call and then does extensive post-processing of the results. I would like the processed ...
0
votes
2answers
25 views
Scope issue in $http success callback
I'm using PHP to get data into my factory, which shows correctly in the success callback function within the controller. However, even after assigning the returned data to $scope.customers, it's not ...
0
votes
2answers
32 views
Can't get this.var to bind correct data in AngularJs
Two Important Notes:
1. My goal is to AVOID using $scope in this case since it's my understanding that impedes the new "controller as" syntax.
2. My problem is likely a variable scope issue and so ...
0
votes
1answer
78 views
$scope.$emit not working while $rootScope.$broadcast does
Here's my parent controller where I listen for the event
app.controller("SectionLayoutController", function($scope) {
$scope.$on("sectionLayout.doAction", function(e, options) {
// do some ...
0
votes
2answers
35 views
Send Object From Directive to Parent Controller in AngularJS
How can I send an object back from a directive into the parent controller?
I've defined the following directive:
app.directive('inspectorSharedObjects', function () {
return {
restrict: 'E',
...
0
votes
1answer
21 views
Referencing the element that's calling a controller function Angularjs
Fairly simple but I can't figure out the term I need to google.
How do I reference whichever element is calling the controllers blurr function?
html
<body ng-app="test">
<div ...
0
votes
1answer
30 views
Trying to call method in service from a controller
I'm trying to call a method in a service from a controller and am receiving the error: 'TypeError: undefined is not a function'. Does anyone see anything wrong with how I have things set up?
valid.js
...
0
votes
1answer
108 views
How to pass $scope data between two partial files in angularjs
How can I pass data in two partial html files using angularJS, totally weird cant get through it.
I have one index file [fine.], I login and reach view5 [partials/blog.html] which is written in ...
0
votes
3answers
41 views
How to escape an angular scope variable in a kiwi template
I have a scope variable (myVar) which is defined in MyController:
angular.module('myApp.controllers').controller('MyController', ['$scope', function($scope) {
$scope.myVar = 'whatsoever';
}]);
...
0
votes
2answers
194 views
AngularJs ngShow triggers double in controller
I have a problem with the controller triggering the method defined on the $scope twice when the page first loads and when the form submits.
Here's the fiddle : http://jsfiddle.net/scabro/pQb6q/5/
...
0
votes
3answers
91 views
AnuglarJS - Parsing multiple .then in controller from factory data
I have a controller calling to any set of specified methods in a factory to retrieve information on a given date. Some of the methods iterate through a JSON file to return promise. See factory below ...
0
votes
1answer
38 views
Angularjs app logic structure help required
I've recently started with Angular and would really appreciate some help on how to properly structure my code the angular way. This is more of a meta question rather then technical question.
I have ...