angularjs-controller

How to access the $ngModelController from inside the Controller without a Form and without a Directive

こ雲淡風輕ζ 提交于 2019-11-28 07:20:19
问题 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): <input type="text" ng-model="inicio" name="inicio" ui-mask="99/99/9999"> // inside my controller $scope.inicio = dateFilter((new Date).getTime(), 'dd/MM/yyyy'); ui-mask set the $modelValue a different value than $viewValue, making it hard to send formatted data to the server. When the $scope.inicio

Load controller dynamically based on route group

帅比萌擦擦* 提交于 2019-11-28 06:36:38
Is it possible to load a controller, it's js file, and a template dynamically based on a route group? Psuedo code which doesn't work: $routeProvider.when('/:plugin', function(plugin) { templateUrl: 'plugins/' + plugin + '/index.html', controller: plugin + 'Ctrl', resolve: { /* Load the JS file, from 'plugins/' + plugin + '/controller.js' */ } }); I've seen a lot of questions like this one but none that loads the js file/controller based on a route group. I managed to solve it inspired by @calebboyd, http://ify.io/lazy-loading-in-angularjs/ and http://weblogs.asp.net/dwahlin/archive/2013/05/22

Why wouldn't you use explicit annotations when defining controllers in AngularJS?

寵の児 提交于 2019-11-28 05:12:08
问题 I am new to AngularJS and learning about the two styles of writing controller functions. It seems as though the only reason someone would not use explicit annotations is to save time, which doesn't seem like a good reason. And being able to minify/obfuscate code seems like a requirement I would want to keep in any application. Also note that I am not asking which is better or asking for a debate. I am asking for what reasons (or in what situation) it would be more beneficial to not use

Simple Angular $routeProvider resolve test. What is wrong with this code?

醉酒当歌 提交于 2019-11-28 01:11:38
问题 I have created a simple Angular JS $routeProvider resolve test application. It gives the following error: Error: Unknown provider: dataProvider <- data I would appreciate it if someone could identify where I have gone wrong. index.html <!DOCTYPE html> <html ng-app="ResolveTest"> <head> <title>Resolve Test</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.js"> </script> <script src="ResolveTest.js"></script> </head> <body ng-controller="ResolveCtrl"> <div ng

angularjs - how to get in the controller the index of an item in a ng-repeat filter based on the value of one of its properties?

雨燕双飞 提交于 2019-11-27 23:19:01
I use a ng-repeat in my html file to display filtered items: <li ng-repeat="item in (filteredItems = (items | filter:query))"> {{ item.name }} </a> In the controller, I'd like to get the index of an item based on one of his property. Precision: I'd like to get the index in the filtered list and not in the whole list. Here for example, it will be the index of the item witch name is some_item_7 . var app = angular.module('myApp', []); app.controller('MyCtrl', ['$scope', function MyCtrl($scope) { $scope.query = 'some'; $scope.items = [ { name: 'some_item_1' }, { name: 'another_item_2' }, { name:

How to share the $scope variable of one controller with another in AngularJS?

你说的曾经没有我的故事 提交于 2019-11-27 21:04:16
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 I accomplish this? You could use an Angular Service to share variable acrosss multiple controllers. angular.module('myApp', []) .service('User', function () { return {}; }) To share the data among independent controllers, Services can be used. Create a service with the data model that needs to be shared. Inject the service in the respective controllers. function ControllerA($scope, User) { $scope.user =

Accessing inherited scope with Controller As approach

烂漫一生 提交于 2019-11-27 18:42:34
With the original way to define controllers , accessing the parent's scope was fairly trivial, since the child scope prototypically inherits from its parent. app.controller("parentCtrl", function($scope){ $scope.name = "Parent"; }) .controller("childCtrl", function($scope){ $scope.childName = "child of " + $scope.name; }); <div ng-controller="parentCtrl"> {{name}} <div ng-controller="childCtrl"> {{childName}} </div> </div> The Controller-As approach seems to be the recommended way to declare a controller. But with Controller-As, the above approach no longer works. Sure, I can access the parent

Reinitialize an Angular.js controller

别来无恙 提交于 2019-11-27 17:23:09
问题 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 it would be very convenient not to have to reset every variable to it's initial value, especially if what you really want is a simple reinitialization of the controller and the scope. Navigating to the same URL again via $location.path() doesn't help, though. Edit: Suppose I can't use any $window

Linking one controller to another to call service on ng-click

馋奶兔 提交于 2019-11-27 09:54:20
I have two templates with respective controllers and service files. One template's(fleetListTemplate) controller(fleetListController) loads data from its service file(fleetService) and displays in its view(fleetListTemplate). When this happens, and I click on one of the loaded data from fleetService, I should link fleetListController to fleetSummaryController to get data from its service file (fleetSummaryService) and display in fleetSummaryTemplate view. Can someone please help me with the coding? Thank you. The following are the respective modules, templates, controllers and service files.

AngularJS ng-controller not working

大城市里の小女人 提交于 2019-11-27 02:36:18
问题 I just now started learning on AngularJS from w3schools. I am trying to practice examples what ever they have mentioned in the tutorials. Every thing works fine but when i came to "AngularJS Controllers" it is not working properly as working well in w3schools Try it Yourself ». I ve forked my code into this fiddle example. My script looks like this: function personController($scope) { $scope.firstName= "John"; $scope.lastName= "Doe"; } Try to help me out and suggest me a good tutorial(or any