The AngularJS controller exposes the data that is to be displayed into the html view. It plays the essential role of the ModelView in the MVVM design pattern. The view is a part of the HTML template.
1
vote
1answer
23 views
How to test a directive which uses ngModel on same element
I have a directive which requires ngModel. In its link function it calls $setViewValue on the ngModel controller. I want to test that $setViewValue is being called under the right conditions, but I ...
-1
votes
1answer
19 views
TypeError: value is undefined angularjs
I have a controller
.controller('ArticlesCtrl', function($scope) {
$scope.sum = function(value) {
return value.reduce(function(total, article) {
return total + article.price;
}, 0); ...
0
votes
2answers
42 views
Triggering angular form validation from a click handler
I have a form that was moved into a table, losing the built in form validation features as I cannot use ng-submit:
<tr ng-form="controller.add.form">
<td>New item</td>
...
0
votes
2answers
11 views
AngluarJS filter table population by user id
I'm trying to filter a GET call by user id. I keep getting an error that says the userId is undefined. I'm not entirely sure how to properly set up my factory. Do I need to put a getter and setter ...
0
votes
2answers
39 views
AngularJS: What's the correct syntax to share a factory service among custom directives with controllers?
I've 2 custom directives and a controller that all need to share some data. The following doesn't compile. What's the correct syntax to do this?
flight-service.js (shared):
(function() {
var app = ...
1
vote
3answers
53 views
How can I have multiple controller files?
SOLVED
So after viewing your responses and making minor changes to my code, I found a simple typo which prevented me to reach the result I was after. So thank you all to helping with where I was ...
0
votes
0answers
24 views
$interval continues to run when I go from one state to other using route
I have a application in which I have to show a page time-out timer progress bar. I am doing it using $interval. But When I go from one state to other the $interval doesn't get cleared and the shows ...
0
votes
2answers
35 views
How to access the data after post in Angularjs
My Viewer
<button type="submit" ng:click="sendviewer(vl.viewerid)" ></button>
My Controller
$scope.viewerDetails = [];
var viewerid = [];
$scope.sendviewer = function(viewer){
var ...
1
vote
0answers
27 views
How to validate angular form in controller
How can I validate my angular form in controller? I need to check form and depends on validity show block of text
I've used an example of form from official angularjs website.
And can somebody ...
1
vote
2answers
59 views
Access AngularJs directive variable inside controller
I'm little bit new to Angularjs. What I want is access "$scope.myVar" variable inside 'myController' controller. It would be great help if you can provide a solution.
...
2
votes
1answer
42 views
How exactly works the AngularJS application component (module, factory, controller) definition?
I am absolutley new in AngularJS and pretty new in JavaScript and I have the following doubt related to this example showed into a tutorial:
// Creates values or objects on demand
...
0
votes
0answers
23 views
how to attach variable to custom data to state object in ui-router?
I want to attach the the variable which came from controller to data object
.state('403', {
url: '/403',
templateUrl: '403.tmpl.html',
controller: function($scope, $state, APP, Auth) {
...
1
vote
3answers
27 views
Reading data from JSON file in Angularjs using a Promise
I have a factory which provides me a promise when getting a json file :
myapp.factory('topAuthorsFactory', function($http, $q) {
var factory = {
topAuthorsList: false,
getList: ...
2
votes
1answer
32 views
how to bind the relevant value in case of current status in ui-router?
I have attached data attribute in each .state to identify the user (authenticated or public) as following (one state example)
$stateProvider
.state('admin-panel.public.home', {
url: '/p',
...
1
vote
2answers
35 views
How to attach the controller $scope variable to $state data in ui-router?
In my code I want to attach the $scope.requireLogin value to requireLogin of data. How can I get this in this .state?
.state('403', {
url: '/403',
templateUrl: '403.tmpl.html',
...
1
vote
1answer
28 views
Call controller method on angular
This is the fist angular app that I try to make ,let's see
var app = angular.module('miApp', []);
app.controller('CochesController', function($scope) {
$scope.coche ={
marca:"Renault",
...
1
vote
1answer
26 views
directive not firing on <Enter> keypress
I was following this SO Post on creating an Enter keypress directive.
Here is my JS, in which I simulate the same functionality:
JavaScript
var app = angular.module('myApp', []);
...
1
vote
0answers
67 views
Upgrading Angular 1.2 to 1.4, controller registers but doesn't run
Solved! It turns out that the project had console.log suppressed, meaning that poor JavaScript was trying to show me errors and failing. Once I got logging back on I was able to see that there ...
0
votes
2answers
28 views
Is it possible to get access to a controller without declaring it?
I have a bit of a weird situation which requires me to pass my controllers to my directives via a directive scope variable. This works great as long as there are only one controller in use per route, ...
0
votes
2answers
32 views
Trying to display content based on JSON type, no controller w/ angular
I have a JSON file that will contain either an array of objects or a string. I am trying to get this to display based on what JSON type is there.
JSON file,
scenario 1 JSON
"thing":{"important":"a ...
1
vote
2answers
37 views
capturing the form data inside the Angularjs controller
I am new to Angularjs. I am having the form data which I need to make a post request to the server passing the data. I have done the UI and controller part inside the angularjs but do not know how to ...
0
votes
1answer
7 views
factory isnt recognized by controller
I have a controller, "ListController", which needs to be populated with server side data.
app.controller("ListController", function(){
var bar = this;
bar.venues = MyFactory.load();
}
and I ...
1
vote
1answer
43 views
AngularJs: Is it possible to pass value to controller or directive from outside?
I'm initialising the controller and directive inside a function that is called somewhere else. So is it possible to send the param value of the function to controller/directive. Here is my code.
var ...
0
votes
1answer
36 views
Pass Laravel Route Variable into AngularJS Controller
What is the best way to pass a Laravel route variable into an AngularJS controller or service?
For example I have a route of domain.com/contacts/87 where 87 is the contact's ID, this route shows the ...
0
votes
1answer
47 views
How to Pass Scope Variable in ng-click and how to access the Parameter in angularJS Function within Controller
How to Pass Scope Variable in ng-click and how to access the Parameter in angularJS Function within Controller ?
My Source Code is
<!DOCTYPE html>
<html>
<script ...
1
vote
2answers
49 views
Directive scope.$watch called after controller function
So I have a controller and directive. I am having trouble understanding why my controller runs after my directive. I have scoured stack trying to find the answer but it seems like most of the answers ...
1
vote
2answers
35 views
Controller not working in Angular JS
I am new to Angular JS. To see the working of controller, I implemented this simple code where two numbers are taken as an input from the users and their sum is calculated in the controller and the ...
0
votes
2answers
42 views
Angularjs - Argument 'homeController' is not a function, got undefined
I have an ionic application that gives me below mentioned error when navigating `homeController's scope.
Here's my app.js file:
var app = angular.module('app', [
//external modules
'ionic',
...
0
votes
0answers
58 views
$scope.variable is undefined - AngularJS [duplicate]
I have a query rather than a problem.
HTML:
<ion-view view-title="Register" ng-controller="RegisterController">
<ion-content>
<div class="padding">
<label class="item ...
4
votes
2answers
32 views
Controller gets initiated twice
I have a simple controller (logincontroller) which gets initiated twice when loading login.html, however I do not know why that happens.
MyApp.js:
angular.module('PVM', [
'Authentication',
...
0
votes
1answer
47 views
how to get the current view contents only in angularjs controller?
I'm dealing with md-tabs-wrapper it gives the partial view of each category and a single save button as follow
The existing code for it
<md-dialog aria-label="Profile edit" ...
0
votes
0answers
32 views
Angular controller: access scope of parent directive
I have a directive myDirective with a nested controller myCtrl (Yes I know that's not a good design practice and I'll be refactoring it later, but I don't have the time to refactor it right now). In ...
0
votes
1answer
41 views
Setting a two-way bound directive attribute in the HTML with AngularJS
I'm just starting out with AngularJs and have run into an issue that might be the result of not understanding directives / controllers /isolated scope properly. I'm trying to find a way to set a ...
1
vote
2answers
38 views
how to do easily the group of filtering conditions in angularjs?
I have four filtering such as JobType,Experience,DateAdded and Salary i want to do filtering as individual and group. For it i defined a filter as filterType in my controller and added to template ...
0
votes
2answers
52 views
Function in Controller not being hit
First time asking a q, so if I'm doing something wrong, please let me know so I can fix it as I have tried finding the answer on here, but can not, so any and all help would be greatly appreciated.
...
0
votes
2answers
39 views
How to share a variable between multiple modules in AngularJS
I'm new to AngularJS and understand the basic principles. However, I'm having a case now where I don't yet know how to get to the solution.
Let me briefly explain you the case. Let's say you have a ...
16
votes
5answers
409 views
AngularJS controllers, design pattern for a DRY code
I have created a full example for the purpose of describing this issue. My actual application is even bigger than the presented demo and there are more services and directives operated by every ...
0
votes
1answer
29 views
Pass object down to the child directive results in unexpected undefined
It's like third day im confused by this, and I'm going crazy already.
The intro
I'm writing an app in which, among others, I'm registering people - creating entry for person with plenty of related ...
0
votes
2answers
62 views
AngularJS - $rootScope variable initialization fails
I'm trying to initialize a $rootScope array variable (arrayX) and use it in a $rootScope function in the same controller (controllerA).
The reason i'm using $rootScope instead of $scope for this ...
0
votes
1answer
35 views
How to use variable from a Controller in a Directive link function?
I want to be able to use the variable "videoUrlId" from the controller 'useSpreadsheetData' below in my directive 'meetings'. How can I do this? I have looked at require but could not get it to work.
...
1
vote
1answer
35 views
Directive hierarchy & bindToController
I encountered an issue while writing an AngularJS directive.
I'm actually trying to melt two principles, directive inheritance and using the controller object (the famous this) instead of $scope.
I ...
1
vote
1answer
18 views
Induce controller UI change from within directive with shared variable
So i have a controller which hides/shows part of its template based on value, let's say its something like this:
<div ng-show="isSelected"></div>
...
$scope.isSelected = true;
...
...
1
vote
5answers
47 views
How to access the scope of a parent's controller's in a directive's controller?
I have a custom directive nested in a parent div who's controller sets a variable value to its scope, such as:
html
<div ng-controller="mainCtrl">
<p>{{data}}</p>
...
0
votes
0answers
30 views
Detect Forward and Backward Routes througth a Button - AngularJS
Plenty of folks have asked how to detect back button clicks/gestures in AngularJS but that is really only half of the equation.
In order to use ngAnimate transitions, specifically a slide left on ...
0
votes
2answers
21 views
How to read the concatenated string as a variable in angularjs?
In my angular controller i defined
$scope.flag1 = false;
$scope.flag2 = false;
$scope.flag3 = false;
I need to read those variable in my view page as bellow
<div flex="30" flex-sm="100" ...
0
votes
1answer
32 views
how to change the custom attribute value using angularjs controller?
i have used material design class in my app.
<div flex="30" flex-sm="100" ng-repeat="shortListLoad in user.shortListLoads">
<md-button class="md-icon-button md-primary" ...
0
votes
1answer
59 views
How to update Directive on State Changes
I have a root state that defines the overall structure of the Angular template. In the root state, I have the sidebar included that has dynamic menus via directive that changes based on the state. ...
0
votes
2answers
24 views
$scope.$watch() is not picking up service object changes
I've written a service for extending the offcanvas library. It's all dandy however I can't seem to get the state object to propagate to my controller.
I'm watching for state changes but nothing seems ...
1
vote
3answers
43 views
How exactly is an AngularJS controller defined?
I have a question related to the syntax of controllers and the way they are declared in AngularJS. I'm fairly certain I know how they work, but my question is related to the syntax.
So I might have ...
0
votes
1answer
56 views
angularjs - get from a factory returns null on page refresh
I have two controllers(and two views) and a factory. I set a property in the factory from the first controller.Then I redirect to the second page. When I try to get the property from the factory in ...