angularjs-controller

Angular-ui bootstrap modal without creating new controller

安稳与你 提交于 2019-12-03 10:49:14
plunk: http://plnkr.co/edit/85Wl5W If I use the $modalInstance on the same controller(modalController.js), without being in a modal, angular gets frozen. I just want to simplify my life using angularjs with the angular-ui bootstrap modal service. I want to use the same controller on a separate file, but on a modal as well. That is, I want them to do the same task. Is there any proper way to do it? E.g. modal.html, modalController.js. I want to show these on a modal window, but on my application as well without a modal. The issue is that if I use the same controller I can't inject the

AngularJS: Inject controller inside another controller from the same module

隐身守侯 提交于 2019-12-03 10:07:13
Is possible to inject a controller into another controller that is part of the same module? example: var app = angular.module('myAppModule', []) .controller('controllerOne', ['$scope', function($scope){ $scope.helloWorld = function(){ return 'Hello World'; } }]) .controller('controllerTwo', ['$scope', 'controllerOne', function($scope, controllerOne){ console.log(controllerOne.helloWorld()); }]) I keep getting unknown provider on controllerOne. I don't see how that's possible since they coexist in the same module. Any help would be much appreciated. You need to use $controller dependency by

Nested directives - cannot pass args to controller method from child directive in Angularjs

被刻印的时光 ゝ 提交于 2019-12-03 07:30:30
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 undefined. I'm attempting to call remove() with three arguments from selected.html below. It was working before I introduced a parent directive (televisionFilter.js) Can anyone suggest what to do to pass these to the controller? Thanks! Code: controller.js $scope.remove = function(selectorToRemove, choicesArr, selectedArr){ console.log(selectorToRemove); //undefined console.log(choicesArr); //undefined

Assign multiple controller in $stateProvider.state

假如想象 提交于 2019-12-03 05:39:27
Probably this is an easy question for advanced angular users, but I did not find this issue somewhere well explained. So I was restructuring my code, when I realized, I have two controllers in a view, which is not a problem, when controller 'ACtrl' is binded by the $stateProvider and controller 'BCtrl' is binded in the view by ng-controller. But when I try to assign both of them in the $stateProvider like this: $stateProvider.state('a.view', { url: "/anurl", views: { 'menuContent': { templateUrl: "anUrlToMyTemplates", controller: 'ACtrl', 'BCtrl' } } }); or that: $stateProvider.state('a.view',

How to reuse one controller for 2 different views?

落花浮王杯 提交于 2019-12-03 04:27:51
I have defined one controller, and apply it to 2 views with small differences. Angular code: app.controller('MyCtrl', function($scope) { $scope.canSave = false; $scope.demo = { files : [{ filename: 'aaa.html', source: '<div>aaa</div>' }, { filename: 'bbb.html', source: '<div>bbb</div>' }] } $scope.newFile = function(file) { $scope.demo.files.push(file); } $scope.$watch("demo.files", function(val) { $scope.canSave = true; }, true); }); View 1: <div ng-controller="MyCtrl"></div> View 2: <div ng-controller="MyCtrl"></div> The sample code is very simple, but there are a lot of code and logic in my

Calling directive's methods from parent controller in AngularJS

≯℡__Kan透↙ 提交于 2019-12-02 22:03:43
I am using AngularJS with the alias controllers pattern. I can't access (or I don't know how to) directive methods from a parent controller. I have a function inside my controller that should call a directive method but this directive method is not available inside the this controller value. This is what I have. What I am doing wrong? JS angular.module('myApp', []). controller('MyCtrl', function(){ this.text = 'Controller text'; this.dirText = 'Directive text'; this.click = function(){ this.changeText(); } }) .directive('myDir', function(){ return { restrict: 'E', scope: { text: '=' }, link:

Communication between controllers in Angular

戏子无情 提交于 2019-12-02 21:05:38
I'm familiar with the following methods to implement communication between controllers. Are there others? Are there better approaches / best practices? $broadcast / $emit .controller("Parent", function($scope){ $scope.$broadcast("SomethingHappened", {..}); $scope.$on("SomethingElseHappened", function(e, d){..}); }) .controller("Child", functions($scope){ $scope.$broadcast("SomethingElseHappened", {..}); $scope.$on("SomethingHappened", function(e, d){..}); }) .controller("AnotherChild", functions($scope){ $scope.$on("SomethingHappened", function(e, d){..}); }); or, from the View: <button ng

How to inject parameters into an inline controller function in $uibModal

微笑、不失礼 提交于 2019-12-02 19:09:50
问题 I'm having a problem with $uibModal's open function, specifically injecting my parameters properly into an inline controller function. Being the angularjs noob that I am, I've tried several things, none of which I can get to work. I'm using Visual Studio Code to write the angular, and gulp to build it. My first attempt (using an inline function): var modalInstance = $uibModal.open({ animation: false, templateUrl: 'app/workform/LoanActions/LoanActionOverpay.modal.html', controller: function (

Retrieving data out of post success from separate controller angularjs

南笙酒味 提交于 2019-12-02 17:28:16
问题 I am writing a simple service that uploads a file and posts it to a Spring controller. The controller manipulates this data and returns several objects as JSON. I am working with the following Angular service: myApp.service('fileUpload', [ '$http', function($http) { this.uploadFileToUrl = function(file, uploadUrl) { var fd = new FormData(); fd.append('file', file); $http.post(uploadUrl, fd, { transformRequest : angular.identity, headers : { 'Content-Type' : undefined } }) .success(function

Using $setValidity inside a Controller

匆匆过客 提交于 2019-12-02 15:41:58
I am trying to do some validation on file change. Here is my code: View/Template <input type="file" name="file" id="file" onchange="angular.element(this).scope().setFile(this)" required /> <span class="error" ng-show="myForm.file.$error.required">Error</span> <span class="error" ng-show="myForm.file.$error.size">Selected file is too large</span> <span class="error" ng-show="myForm.file.$error.filetype">Unsupported File type</span> Controller angular.module("myapp").controller("myctrl", function($scope) { $scope.setFile = function(element) { $scope.$apply(function($scope) { var fileObject =