ng-controller

AngularJS - convert dates in controller

岁酱吖の 提交于 2019-11-26 12:56:50
Could anyone please suggest me how to convert date from this 1387843200000 format into this 24/12/2013 inside my controller ? Just FYI my dates are stored in this way & when binding to edit form with input type="date" field is not being populated at all. #Plunker demo here. EditCtrl app.controller("EditCtrl", [ "$scope", "$filter", "db" function ($scope, $filter, db){ // this gets me an item object var item = db.readItem(); // item date = 1387843200000 // this returns undefined item.date = $filter('date')(date[ item.date, "dd/MM/yyyy"]); }]); Edit.html - template <form name="editForm" class=

Easiest way to pass an AngularJS scope variable from directive to controller?

醉酒当歌 提交于 2019-11-26 12:36:19
What is the easiest way to pass an AngularJS scope variable from directive to controller? All of the examples that I've seen seem so complex, isn't there a way I can access a controller from a directive, and set one of it's scope variables? Edited on 2014/8/25: Here was where I forked it. Thanks @anvarik. Here is the JSFiddle . I forgot where I forked this. But this is a good example showing you the difference between = and @ <div ng-controller="MyCtrl"> <h2>Parent Scope</h2> <input ng-model="foo"> <i>// Update to see how parent scope interacts with component scope</i> <br><br> <!-- attribute

Angularjs: &#39;controller as syntax&#39; and $watch

浪子不回头ぞ 提交于 2019-11-26 08:45:31
问题 How to subscribe on property change when using controller as syntax? controller(\'TestCtrl\', function ($scope) { this.name = \'Max\'; this.changeName = function () { this.name = new Date(); } // not working $scope.$watch(\"name\",function(value){ console.log(value) }); }); <div ng-controller=\"TestCtrl as test\"> <input type=\"text\" ng-model=\"test.name\" /> <a ng-click=\"test.changeName()\" href=\"#\">Change Name</a> </div> 回答1: Just bind the relevant context. $scope.$watch(angular.bind

AngularJS - convert dates in controller

非 Y 不嫁゛ 提交于 2019-11-26 03:08:49
问题 Could anyone please suggest me how to convert date from this 1387843200000 format into this 24/12/2013 inside my controller ? Just FYI my dates are stored in this way & when binding to edit form with input type=\"date\" field is not being populated at all. #Plunker demo here. EditCtrl app.controller(\"EditCtrl\", [ \"$scope\", \"$filter\", \"db\" function ($scope, $filter, db){ // this gets me an item object var item = db.readItem(); // item date = 1387843200000 // this returns undefined item

Easiest way to pass an AngularJS scope variable from directive to controller?

淺唱寂寞╮ 提交于 2019-11-26 03:03:08
问题 What is the easiest way to pass an AngularJS scope variable from directive to controller? All of the examples that I\'ve seen seem so complex, isn\'t there a way I can access a controller from a directive, and set one of it\'s scope variables? 回答1: Edited on 2014/8/25: Here was where I forked it. Thanks @anvarik. Here is the JSFiddle. I forgot where I forked this. But this is a good example showing you the difference between = and @ <div ng-controller="MyCtrl"> <h2>Parent Scope</h2> <input ng

How to use a filter in a controller?

泄露秘密 提交于 2019-11-25 23:23:49
问题 I have written a filter function which will return data based on the argument you are passing. I want the same functionality in my controller. Is it possible to reuse the filter function in a controller? This is what I\'ve tried so far: function myCtrl($scope,filter1) { // i simply used the filter function name, it is not working. } 回答1: Inject $filter to your controller function myCtrl($scope, $filter) { } Then wherever you want to use that filter, just use it like this: $filter('filtername'