angularjs-scope

Angular JS executing function $timer within $scope receives TypeError

喜夏-厌秋 提交于 2019-12-11 11:22:12
问题 Why is that when using $timeout in Angular JS that is inside function like the following, works fine. var mytimeout = $timeout(function(){ console.log("MyTimeout Executed"); },2000); mytimeout.then( function() { console.log( "mytimeout resolved!", Date.now() ); }, function() { console.log( "mytimeout rejected!", Date.now() ); } ); but when I use $timer with a function inside $scope it does not work, like this: $scope.myFunction = function(){ console.log("MyTimeout Executed"); }; var mytimeout

How to separate scopes of buttons inside a reusable directive

岁酱吖の 提交于 2019-12-11 11:17:30
问题 I need to have a reusable directive with several buttons.But my problem is when I try to use the same directive multiple times the buttons binds to one single scope. For example see the code below: <body ng-controller="MainCtrl"> <test></test> <test></test> </body> Code for test directive is app.directive("test",function(){ return{ restrict:"E", scope:{ }, template:"<input type='button' value='click me!' onclick='clickD()'>", controller:function($scope){ clickD=function() { alert($scope.$id);

Angularjs - Updating multiple instances of the same controller

心已入冬 提交于 2019-12-11 11:14:56
问题 My problem: I have multiple instances a controller in my site. When I update 'x', only the current instance/div gets updated. JSFiddle: http://jsfiddle.net/evgahe2u/ (simplified example, each ng-controller is in its own view.) HTML <!-- this is a simplified example --> <div ng-app="myApp"> <!-- this is in view1.html --> <div ng-controller="myController"> <input type="text" ng-model="x" /> {{x}} </div> <!-- this is in view2.html --> <div ng-controller="myController"> <input type="text" ng

when a radio button is in ng-repeat when i click on radio button the div will be enable?

旧时模样 提交于 2019-12-11 11:10:53
问题 Here when i click on radio button the following div should be disable if the checked radio button is equals to sj.But here its not working if i use ng-repeat for radio button same is working if its static.Could any one help me out what is the mistake i have done here? <div ng-app="plunker"> <div class="wrap" ng-controller="MyCtrl"> <h1>Hello there!</h1> <p>Push the radio buttons to change the content!</p> <form> <div ng-repeat="s in color"> <input id="first" type="radio" name="content" ng

angularjs - custom directive in ng-include not working

强颜欢笑 提交于 2019-12-11 10:49:12
问题 I've tried this snippet for using bs3 modal in my application and it works fine. http://jsfiddle.net/alexsuch/RLQhh/ However,I want to wrap the code of modal and some other html tags into a template for reusability. <div ng-controller="MainCtrl" class="container"> <h1>Modal example</h1> <button ng-click="toggleModal()" class="btn btn-default">Open modal</button> <div ng-include src="'modal.html'"></div> <script type="text/ng-template" id="modal.html"> <modal title="Login form" visible=

how to know which element is selected in angular js

强颜欢笑 提交于 2019-12-11 10:48:57
问题 I make multiple selected popover , in which user can select multiple values . I want to print the all selected value on screen or get a object in which all element which is selected by user .I will explain in other words .In my demo I have one button on screen .On button click I open a pop over which have multiple selected element I want to get all element which is selected by user in pop up please check my demo .here is my demo http://codepen.io/anon/pen/KpaejV angular.module('ionicApp', [

how to add click event to angular js directive for plotting flot bar chart

馋奶兔 提交于 2019-12-11 10:40:09
问题 I am pretty new to angularjs and flot charts. I am trying to add click events to my stacked bar charts so that once I click a stack it displays the categories information but I am not sure if am doing it right. Please help take a look I already plot my chart in angularjs directive see http://jsfiddle.net/6h1gL2sh/10/ here App.directive('chart', function () { return { restrict: 'EA', link: function (scope, elem, attrs) { var chart = null, options = { series: { stack: true, bars: { show: true,

Watching subvalues of array

我的梦境 提交于 2019-12-11 10:37:57
问题 I have a dynamic array with items, which could look like this: $scope.items = [ {id: 1, name: 'Ford', checked: false}, {id: 2, name: 'Mercedes', checked: true}, {id: 3, name: 'BMW', checked: false} ]; I want to react whenever a checked value is changed, and know which item it was changed on. How can I achieve this? 回答1: You could register an ng-change event to the check boxes bound. If you indeed really want to add a watch you can use the deep watch option. $scope.$watch('items', fn, true) .

Angular is not recognizing global functions as controllers [duplicate]

徘徊边缘 提交于 2019-12-11 10:36:40
问题 This question already has answers here : Controller not a function, got undefined, while defining controllers globally (14 answers) Closed 4 years ago . Using Angular 1.3.x, global functions are not recognized as controllers. What's going wrong? How do I correct this? function MyController() { // etc } <div ng-controller="MyController"></div> The console shows the following error: Error: [ng:areq] http://errors.angularjs.org/1.3.2/ng/areq?p0=MyController&p1=not%20a%20function%2C%20got

How do you set $rootScope within Angular Service function?

限于喜欢 提交于 2019-12-11 10:36:11
问题 I'm having trouble setting $rootScope for Angularjs. Below is my function App.controller('Controller', function (UtilityService, $rootScope) { var setSession = function () { $rootScope.test = "yes"; // <-- I get this UtilityService.getSession().success( function () { $rootScope.test = "No"; // <-- I don't get this How do I get/set this value? }); }; setSession(); }); Additional Info: One of the ways that might work is to set up a service that is interacted between multiple controllers. Does