angularjs-controller

Using controller inside another controller in AngularJS

[亡魂溺海] 提交于 2019-12-04 20:06:18
问题 Why I can't bind to controller's variable inside second controller? <div ng-app="ManagerApp"> <div ng-controller="MainCtrl"> Main: <div ng-repeat="state in states"> {{state}} </div> <div ng-controller="InsideCtrl as inside"> Inside: <div ng-repeat="state in inside.states2"> {{state}} </div> </div> </div> </div> var angularApp = angular.module('ManagerApp', []); angularApp.controller('MainCtrl', ['$scope', function ($scope) { $scope.states = ["NY", "CA", "WA"]; }]); angularApp.controller(

Access AngularJs directive variable inside controller

和自甴很熟 提交于 2019-12-04 19:25:38
问题 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. angular.module('myDirective', []) .controller('myController', ['$scope', function ($scope) { }]) .directive('myDirective', function () { return { scope: { myVar: '=' }, controller: function ($scope) { $scope.myVar = 'xyz'; alert($scope.myVar); } }; }); <html lang="en-US"> <script src="http://ajax.googleapis.com/ajax/libs

how to bind the relevant value in case of current status in ui-router?

感情迁移 提交于 2019-12-04 16:42:52
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', templateUrl: 'app/public/home.tmpl.html', controller: 'PublicHomeController', controllerAs: 'ctrl', data: { requireLogin: false } }); I need to use the some state for both of user (authenticated and public) as an example .state('403', { url: '/403', templateUrl: '403.tmpl.html', controller: function($scope, $state, APP, Auth) { $scope.app = APP; $scope.goHome = function() { if(Auth.isAuthenticated()){ $scope

AngularJS: Inject controller inside another controller from the same module

微笑、不失礼 提交于 2019-12-04 16:08:35
问题 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

how to display youtube thumbnail image from url with Angularjs

谁说胖子不能爱 提交于 2019-12-04 12:58:00
I just start to using angularjs and I want to display youtube thumbnail image from the youtube video url ... is there a way to display video thumbnail when people insert url in input and then click the button, PLUNKER http://plnkr.co/edit/9SBbTaDONuNXvOQ7lkWe?p=preview Pankaj Parkar Youtube provide default thumbnail image of its video. You can use below sample URL to create thumbnail image. http://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg Where you need to search id from the given url & create url like above will give you thumbnail image. Controller app.controller('MyCtrl',

AngularJS: How to share scope functions and variables with other controllers

℡╲_俬逩灬. 提交于 2019-12-04 11:27:08
I've multiple controllers in my application, where I have some duplicate code like: $scope.alert = null; $scope.addAlert = function (message) { $scope.alert = { type: 'danger', msg: message }; }; $scope.clearAlerts = function () { $scope.alert = null; }; What is the recommended way sharing these scope functions and variables in AngularJS? Using controller inheritance? Create a one controller and then place common methods inside that controller scope. So that you can use that scope anywhere else and get access to method inside controller. Controller app.controller('commonCtrl', function($scope)

Calling directive's methods from parent controller in AngularJS

谁都会走 提交于 2019-12-04 08:28:49
问题 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

Angular minification with directive controller?

元气小坏坏 提交于 2019-12-04 04:46:27
If I have the following: myapp.directive('directivename', ... return { ... restrict: 'E', controller: MyController, ... } function MyController($scope, $somethingelse) { // Contents of controller here } ); How do I modify this such that MyController will not get destroyed when minified? I am getting the following error: Error: [$injector:unpr] Unknown provider: eProvider <- e PSL It can be resolved by using explicit dependency annotation. What you have it implicit annotation which causes issues while minification. You could use $inject or inline array annotation to annotate the dependencies in

AngularJS Modules and External Controllers

喜欢而已 提交于 2019-12-04 02:07:29
问题 I have a page containing multiple containers. Each container will have its own controller but point to one factory, which handles all the logic interacting with a web service API. I would like to have a separate file for each controller BUT I want all of this inside of one module. for the life of me I cannot find how to include controllers from different files into one modules. //file 1 MyController .... //file 2 MyOtherController //file 3 MyFactory //file 4 The Module The module would be

How to reuse one controller for 2 different views?

你。 提交于 2019-12-03 14:41:01
问题 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