angularjs-scope

How to exchange a value from pop-up to parent window in AngularJS

僤鯓⒐⒋嵵緔 提交于 2019-12-07 22:38:12
问题 I have a scenario where I need to exchange the data dynamically ( From PARENT To CHILD and Reversal ( PARENT to CHILD ) ). I referred from couple of links and it helped me to pass the data from PARENT to CHILD, however From CHILD to PARENT didn't . Below i have the source code of Parent to Child (Html as well as the controller). Could somebody help me how to take the data back again. Parent.html <!DOCTYPE html> <html ng-app="parentWindowApp"> <head> <title>Parent Window</title> <meta http

Benefits/drawbacks of additional abstraction layer within Angular's $scope

99封情书 提交于 2019-12-07 22:34:51
问题 I have slightly modified the example from the following URL (http://docs.angularjs.org/cookbook/helloworld) as follows, placing the name value within an attrs object property: <!doctype html> <html ng-app> <head> <script src="http://code.angularjs.org/1.2.9/angular.min.js"></script> <script> function HelloCntl($scope) { $scope.attrs = { name : 'World' } } </script> </head> <body> <div ng-controller="HelloCntl"> Your name: <input type="text" ng-model="attrs.name"/> <hr/> Hello {{attrs.name ||

AngularJS: Alerts don't show up when multiple messages change ngModel for message

人盡茶涼 提交于 2019-12-07 22:07:17
问题 I have a notification service which works well for when page is loaded and Controller is loaded But when I have different buttons calling different functions, they change message, but alerts don't show up Here is a plunker for that - http://plnkr.co/edit/YioiJXNkaET6T2mexjCq?p=preview What is that I need to do to update it whenever $scope.message changes? 回答1: You could $watch the model and show the alert when it changes. http://plnkr.co/edit/fJuP9LWH4MNVV1cQs3ED?p=preview In linker function

How to pass vm to a setTimeout in AngularJs? Changes to scope don't update DOM view

坚强是说给别人听的谎言 提交于 2019-12-07 19:37:28
I'm trying the following code. Everything seems to be working as I see the component appear/disappear depending on the value I set for the variable. However, when I do that in the setTimeout(...) function, it starts to misbehave. The poofy text shows but the value set to vm doesn't. My guess is that I need to pass it in somehow but I'm not sure how. (function () { 'use strict'; angular .module("app") .controller("Banana", banana); function banana() { var vm = this; vm.showStuff = false; setTimeout(function () { console.log("poof!"); vm.showStuff = true; }, 1000); } })(); Do I need to make the

ng-repeat and ng-switch doesn't work on same element

佐手、 提交于 2019-12-07 19:23:03
问题 JS $scope.mode = "test" $scope.array = ['test1', 'test2', 'test3'] HTML <div ng-switch on="mode"> <div ng-repeat="item in array" ng-switch-when="test"> Test {{item}} </div> </div> When I do this the above, the output I get is Test Test Test It can't seem to access item. If I remove the ng-switch-when then it works fine. 回答1: It is because ng-switch creates a child scope and same applies for ng-repeat. ng-repeat runs at priority 1000 and ng-switch at 800 . So the child scope created by ng

Get empty model from backend in angularjs factory and update controller variable upon success

巧了我就是萌 提交于 2019-12-07 18:28:12
问题 This is my factory and in my factory http call I am assigning value to my User variable but it is not updating my controller. mainApp.factory('AccountFactory', ['$http', function ($http) { var User = { }; function getLogOnModel() { $http.get("http://localhost/mylocalspecial/Account/LogOn").then(function (data) { User = data.data; alert(JSON.stringify(data.data)); return data; }); } // Init model (or leave it for the controller to init it) getLogOnModel(); return { User: User, getLogOnModel:

Call Angular controller from script onload

喜欢而已 提交于 2019-12-07 16:23:12
问题 I am trying to update the state of my controller after loading of a script from onload callback. I load the Google Client API: <script src="https://apis.google.com/js/client.js?onload=OnLoadCallback"></script> Then in OnLoadCallback I try to manually bootstrap AngularJS and set the set state on to my controller: function OnLoadCallback() { var $injector = angular.bootstrap(document, ['app']); // load required gapi APIs var $controller = $injector.get('$controller'); var UserCtrl = $controller

How to insert $compile'd HTML code inside the directive without getting $digest recursion error?

风格不统一 提交于 2019-12-07 15:20:37
问题 I have a directive that, depending on the ng-repeat item data (from the database), build custom HTML with a switch case: app.directive('steps', function($compile){ return { 'restrict': 'A', 'template': '<h3>{{step.name}}</h3><ul ng-repeat="opt in step.opts"><div ng-bind-html-unsafe="extra(opt)"></div></ul>', 'link': function($scope, $element){ $scope.extra = function(opt){ switch ($scope.step.id){ case 1: return "<div>Some extra information<select>...</select></div>" case 2: return "<div>

share http.get data between factory and controller

烂漫一生 提交于 2019-12-07 14:16:14
问题 I succesfuly created a factory that gets a .php file output (JSON), My question is how do I access it from wihtin the controller: myApp = angular.module("myApp", []) myApp.factory "mainData", ($http) -> $http.get('gethome.php').success (data) -> data: data console.log(data) myApp.controller "HomeCtrl", ($scope, mainData) -> $scope.home = mainData.data Please let me know if Im choosing the right syntax here, I see lots of examples on how to create a module/controller everywhere in tutorials,

How to get access to a directive attrs with isolated scope?

倖福魔咒の 提交于 2019-12-07 14:14:44
问题 I need to have access to model created by directive and in the same time I need to get attrs in the directive. JS: module.directive('createControl', function($compile, $timeout){ return { scope: { name: '=Name' // Dynamically created ng-model in the directive element }, link: function(scope, element, attrs){ attrs.$observe('createControl', function(){ attrs.createControl //is empty if scope is an object, otherwise it is passed from html attribute } } HTML: <div class="control-group" ng-repeat