angularjs-directive

scope.$watch in directive link function not getting called

被刻印的时光 ゝ 提交于 2019-12-05 05:54:04
I have this factory, .factory('authentication', [function() { return { loginRequired: false }; }]); I have this controller, .controller('TopNavCtrl', ['$scope', 'authentication', function($scope, authentication) { $scope.login = function() { authentication.loginRequired = true; }; }]); and I have this link function in a directive, link: function(scope, element, attrs) { scope.show = false; scope.$watch(authentication.loginRequired, function(value) { scope.show = value; }); } When authentication.loginRequired = true; is done in the controller, the scope.$watch in the directive isn't called. Any

Pass Data $http.post From AngularJS and ASP.net MVC gets null

喜你入骨 提交于 2019-12-05 05:45:38
i'm trying to pass data from AngularJS to ASP.net MVC and is always getting null. Here's my code (only posting the essential, button, controller and c#: HTML: <a class="btn btn-grey btn-lg btn-block" ng-click="AddCar()">Save</a> Controller $scope.AddCar = function () { $http.post("Cars/AddCar", JSON.stringify($scope.new.JsonCar)).success(function (data) { Alert(ok) }) c# public string AddCar(string JsonCar) { try .... } In JSON.stringify($scope.new.JsonCar) i'm getting this: "{"Name":"FIAT 500","Description":"New car","MaxUserCapacity":5,"PhotoPath":"none"}" What i'm doing wrong? Pass your

AngularJS : custom iterations/data transformations and grouping… when simple ng-repeat just won't cut it

。_饼干妹妹 提交于 2019-12-05 05:42:30
问题 Still this problem Angular.js more complex conditional loops but I felt that the answer to the question as it was asked was right so I accepted it. So let me elaborate more than I did in the original question. I'm trying to get this <h3>11.4.2013</h3> <ul> <li>oofrab | 4 | 11.4.2013 14:55 <button>remove</button></li> <li>raboof | 3 | 11.4.2013 13:35 <button>remove</button></li> </ul> <h3>10.4.2013</h3> <ul> <li>barfoo | 2 | 10.4.2013 18:10 <button>remove</button></li> <li>foobar | 1 | 10.4

ASP.NET MVC Partial View in an AngularJS directive

假如想象 提交于 2019-12-05 05:41:37
问题 I'm currently working on an ASP.NET MVC project to which some AngularJS was added - including some AngularJS directives. I need to add to an AngularJS directive a MVC partial view. Obviously, @Html.Partial("_PartialView", {{name}}) doesn't work. So far all my searches online provided no help. Any idea how I could render a partial view inside an Angular directive? Thanks! 回答1: Angular exists strictly on the client side whereas MVC views exist on the server side. These two cannot interact

AngularJS set element fixed position based on another element

泄露秘密 提交于 2019-12-05 05:40:30
This app takes an image, which is essential a background, or workspace. I need to add input text fields onto this workspace given specific coordinates (top, left, width, height). These coordinates would be relative to the image (top/left = 0/0). How would I position my fields/elements relative to the image? <img id="background" ng-src="{{page.backgroundImage}}" /> <input type="text" ng-repeat="field in page.fields" ng-model="field.value" ng-style="{position:'absolute', left:field.left, top:field.top, width:field.width, height:field.height}"/> The code above works great for absolute positioning

AngularJs Directive Template with ng-transclude cannot be compiled

可紊 提交于 2019-12-05 05:38:44
I am trying to create two directives. The first directive appends other predefined angular directives (ng-click and ng-class) to the element and then compiles it so that they work. The second directive replaces an element for a template which contains the first directive. I use ng-transclude to carry the element's contents over to the template. The problem is that once the template from directive 2 is added the first directive tries to compile and throws a wobbly: "TypeError: undefined is not a function" Directive 1 works fine when ng-transclude is not present in the template. I have created a

ng-class within custom directive not observing updates

不想你离开。 提交于 2019-12-05 04:30:17
问题 I'm trying to create a directive that's used like this: <amount value="myValue" neg-class="negative" /> myValue is a scope value (should be a number) negative is simply the name of a css class. The idea behind the directive is that I wan't to show currency to the user and when the amount that's bound is negative, negClass get's applied to the rendered element. The problem I'm having is that when negClass is changed, the update doesn't take effect. I do see the changes in the DOM, though. Here

AngularJS Directive Numeric Format Masking

巧了我就是萌 提交于 2019-12-05 04:15:46
问题 The directive I have created uses the function setFormatting to mask the text value in an input field. scope.$watch(element, function() { modelCtrl.$setViewValue(setFormatting(element.val(), attrs.symbol)); modelCtrl.$render(); }); element.bind('blur', function() { modelCtrl.$setViewValue(setFormatting(element.val(), attrs.symbol)); modelCtrl.$render(); }); The scope.$watch applies the mask when the content is loaded/applied the first time, the element.bind applies the mask for the other

How should I access an element's angularjs $ngModelController in a jasmine unit test?

最后都变了- 提交于 2019-12-05 03:53:10
I'm currently using directiveElement.data("$ngModelController") to get access to the element's $ngModelController , as in the following example. describe("directiveElement", function () { it("should do something with ngModelController", inject(function($compile, $rootScope) { var directiveElement = $compile("<input ng-model="myNgModel" customDirective type="text"></input>")($rootScope); $rootScope.$digest(); var ngModelCtrl = directiveElement.data("$ngModelController"); ngModelCtrl.$modelValue = "12345"; // do rest of test })); }); However, I want to know if there is a better to access the

How do you check if & variable is set in directive

♀尐吖头ヾ 提交于 2019-12-05 03:40:32
In a directive, where you set a method callback through an arg, say: <my-directive callback='showAlert()' /> You can retrieve the variable through the scope setting in the return: scope: { callback: "&callback" } If the callback is not set, eg: <my-directive /> The value of $scope.callback is still: $scope.callback():function (locals) { return parentGet(scope, locals); } Is there a good way to check that the callback was not set? One way i can think off is to check the attribute parameter for the directive name like link: function (scope, elm, attrs) { if(attrs.callback) { //this attribute has