angularjs-scope

Calculate total of rows in ng-repeat with other controller

主宰稳场 提交于 2019-12-13 19:15:15
问题 I got rows where a total will be calculated. In my ng-repeat I have a controller RowCtrl where I calculate the total. app.controller('RowCtrl', function ($scope) { $scope.unit_price = 0; $scope.quantity = 0; $scope.$watchCollection('[row.unit_price, row.quantity]', function () { $scope.row.total = $scope.row.unit_price * $scope.row.quantity; }); }); How can I calculate the total of all the rows? In the fiddlr I have a demo of the rows where the total of a row is already calculated. Fiddlr:

How to encapsulate $scope in Angular.Js

橙三吉。 提交于 2019-12-13 19:07:35
问题 I have a pattern, which I want to use twice, but with different values. For example: .directive("day", function($scope){ return { template: '<div>{{day}}</div>' } } Can I use it in two another directive, but encapsulate 'day' to see result like that: <div>1</div> <div>2</div> Especially if I want to keep binding value of all 'day' 回答1: you meant something like this? app.directive('day', function(){ return { scope: { dayValue: '=' }, template: '<div>{{dayValue}}</div>' } }) app.directive(

Angularjs: ng-model doesn't refresh after object change

房东的猫 提交于 2019-12-13 18:41:29
问题 I'm working with angularjs and I have a little problem with ng-model update. I have a $scope object that is loaded with ajax outside of the ng-controller, in a service. The service is the following: app.factory('myService', function($http) { var myService = { async: function(code) { var promise = $http.get(url).then(function (response) { return response.data; }); return promise; } }; return myService; }); This works, and my $scope object in ng-controller is updated. Now i need to update and

How to use a scope in Directive template

本秂侑毒 提交于 2019-12-13 17:05:57
问题 I want to use $scope variable in template function of directive like this. In the other words i want to generate directive template inside of directive and by using $scope variable. Help me to connect template function to controller. directive("data", ['$compile', '$http', '$templateCache',function ($http,$rootScope) { return{ link: function (scope, elem, attrs, ctrl) { scope.template = something // I want Generate template here }, template:function(element , attrs){ return $scope.template //

Update HTML input value changes in angular ng-model

久未见 提交于 2019-12-13 15:46:04
问题 I have some ng-model input elements that gets updated non-angularJS functions like jquery or sometimes by pure javascript DOM apis. The value on the html input element changes however the model scope variable doesn't get updated. Is there any way to force angular to process these updates app.js After a time-out of 5secs, the value 1 is changed to 999. This is reflected in html but not in $scope.val angular.module('inputExample', []) .controller('ExampleController', ['$scope', '$timeout'

get the value of $scope.data in a variable in same controlled

别等时光非礼了梦想. 提交于 2019-12-13 11:07:15
问题 My code is some thing $scope.data = {}; var init = function () { $http.post('views/Report.aspx/GetMailReport', {}) .success(function (data, status, headers, config) { $scope.data = JSON.parse(data.d); }) .error(function (data, status, headers, config) { $scope.data = status; }) }; init(); var data = $scope.data; But the var data is returning empty {} 回答1: If you want a copy you should do as below... As the http call is asynchronous you assign inside the success callback method $scope.data = {

AngularJS directive get value from scope

心不动则不痛 提交于 2019-12-13 10:31:56
问题 I'm passing my scope object to my directive and this works fine! After a get request I update my scope with a property called project. This contains some values like title, content, etc... If I log this everything is working fine but when I try to log scope.project I get the message undefined, but when I log scope I see the project object in the JSON tree... What can happens here? All console logs show the correct information but I can't access it... directive: .directive('project', ['$http',

[[object Object]] appear on textbox in angularjs [closed]

烈酒焚心 提交于 2019-12-13 10:00:50
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 4 years ago . [object Object] is automatically appeared as value in every textbox in my form. May i know what went wrong? It appears after i inserted the attribute name="searchr" in tag. Thanks. in search.htm: <form ng-submit="search()" ng-controller="formcontrol" name="searchr"> <input type="search" placeholder

Multiple check-box selection and create a tag based on selected option and also filter out the data in AngularJs

时光怂恿深爱的人放手 提交于 2019-12-13 09:54:20
问题 I want to provide multiple selection using check-box and depending on that it will create a tag using angular directive . If user selects multiple check-box then according to that tags should create and if user remove any tag then check-box should be unchecked. So depending on a selection and a removal of tag data should be filter out. Here is my Working CODE Thanks in Advance.! 回答1: Sounds like you are looking for some pre-built code. You can use Angular-multi-select in combination with a

How to use variables from a controller in another controller in AngularJS

流过昼夜 提交于 2019-12-13 08:35:47
问题 I'm new in AngularJS and I want to use the username and password variables that I get in this controller: .controller('LoginCtrl', function($scope, LoginService, $ionicPopup, $state, Api) { $scope.data = {}; $scope.login = function() { LoginService.loginUser($scope.data.username, $scope.data.password) .success(function(data) { $scope.data = {} $state.go('tabs.extranet'); }) .error(function(data) { var alertPopup = $ionicPopup.alert({ title: 'Acceso denegado', template: 'Por favor, compruebe