angularjs-controller

Difference in controller declaration in AngularJS

ぐ巨炮叔叔 提交于 2020-02-15 09:38:20
问题 I have seen controller being declared in two ways as below. But what diff does this make? appmodule.controller('Actrl',['$scope',function($scope) {}]); appmodule.controller('Actrl',function($scope) {}); But, most of the times, the 1st doesn't work. Why? 回答1: Both the syntax are same but the first one is preferred (there is a typo, see below description) if you are minifying your code. Angular resolves the dependency based on the name so when you write appmodule.controller('Actrl',function(

Difference in controller declaration in AngularJS

风格不统一 提交于 2020-02-15 09:37:35
问题 I have seen controller being declared in two ways as below. But what diff does this make? appmodule.controller('Actrl',['$scope',function($scope) {}]); appmodule.controller('Actrl',function($scope) {}); But, most of the times, the 1st doesn't work. Why? 回答1: Both the syntax are same but the first one is preferred (there is a typo, see below description) if you are minifying your code. Angular resolves the dependency based on the name so when you write appmodule.controller('Actrl',function(

How to share a variable between multiple modules in AngularJS

≯℡__Kan透↙ 提交于 2020-02-06 03:41:16
问题 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 supermarket webshop where there is an input box where you can type to search for your food. Next to the input box, there is an icon that displays a modal on click with all the most ordered foods. This modal has it's own controller and the searchpanel in which the inputbox is has it's own controller

Get parent controller in child controller which all use 'controller as vm' notation

[亡魂溺海] 提交于 2020-02-02 04:48:06
问题 Parent controller set to ' parentCtrl as vm ' and chield set to ' childCtrl as vmc ' to be no name conflict and it works well. How can I get access to parent controller in child controller? Note that '$scope.$parent' did not work. 回答1: To access the parent controller using the '$scope' notation just use '$scope.$parent'. However the 'controller as vm' notation lacked a detail that makes it work with some behavior: '$scope.$parent. vm ' app.controller('childCtrl', [ '$scope', function ($scope)

AngularJS : watching Service properties

自闭症网瘾萝莉.ら 提交于 2020-01-25 20:41:09
问题 Take the following plunk as an example: http://plnkr.co/edit/vKFevXhhSprzFvesc6bG?p=preview var app = angular.module('plunker', []); app.service('SomeService', ['$rootScope', function ($rootScope) { var service = { value: false } return service; }]); app.controller('MainCtrl', ['$scope', 'SomeService', function($scope, SomeService) { $scope.value = SomeService.value; //$scope.$watch(function () { return SomeService.value; }, function (data) { $scope.value = data; }); }]); app.controller(

Controller is not registered error after adding ngRoute `.config`

耗尽温柔 提交于 2020-01-25 00:23:07
问题 Controller is not recognizing - AngularJS error I've a controller defined in controllerPloyee.js called controllerPloyee which was working before i added the ngRoute and made to route. The error that shows is angular.min.js:127 Error: [$controller:ctrlreg] http://errors.angularjs.org/1.7.8/$controller/ctrlreg?p0=controllerPloyee I've checked the documentation and another questions with the same error, but doesn't help. Index.html <html ng-app="ployee"> <head> <!--Angular--> <script src="lib

Same “controller as” name in angular js directive breaks function in parent controller

浪尽此生 提交于 2020-01-24 06:46:04
问题 I've a controller with some items for ng-repeat and each item should get a random color so I use ng-style with a function in that controller called randColor(...) . app.controller('TestController', function() { var vm = this; vm.items = [ { name: 'item 1' } , { name: 'item 2'} ]; vm.randColor = function (item) { if (!item) { return 'red'; } else if (!item.color) { var color = 'rgb(' + _.random(0, 255) + ',' + _.random(0, 255) + ',' + _.random(0, 255) + ')'; item.color = color; } return item

AngularJS Unable to display upload file logs [duplicate]

我只是一个虾纸丫 提交于 2020-01-22 04:02:26
问题 This question already has answers here : ng-model for `<input type=“file”/>` (with directive DEMO) (12 answers) Closed 24 days ago . I am trying to create a file upload function using angularjs which will just accept the file and send it to the server side (Django). To ensure the file upload function is working fine, I've placed multiple console.log in multiple locations. However, none of the logs are displayed. This are my codes: .html: <body ng-app="myApp" ng-controller="appCtrl"> <input

Javascript controller -function is not defined

假装没事ソ 提交于 2020-01-17 06:40:11
问题 I posted a post recently but it wasn't easy to read... I hope that with this one you could understand my problem: Basicly i have 2 controllers, and in the first one, I create dinamically a div that has an 'onclick' attribute that calls a function that is on the other controller (newController). The error is: activateSmartcase is not defined. I'm desperate lol.. thanks for help. [EDIT SOLUTION] var myInjector = angular.injector(["ng"]); var $http = myInjector.get("$http"); function funcb($http

How to repeat “key” in ngRepeat one time only (AngularJS)

懵懂的女人 提交于 2020-01-17 04:55:06
问题 The problem is leaving in the JSON Array response from the Backend/DB. I'm getting the response of the database in the correct json format: [ 0: { "Grade": 100, "AB001": 1, "AB002": 0, "AB003": 9, "AB004": 5 }, 1: { "Grade": 98, "AB001": 3, "AB002": 0, "AB003": 0, "AB004": 0 } ... ] (10 objects as result) Thus displayed in the Firebug console, when you click the Response of the GET Request. To retrieve the keys who are represented in double quotes I've used the ngRepeat directive in my view