Search Posts

Category: angularjs-scope

How to retrieve custom property in isolate scope?

I’ve read quite a lot examples on how to do binding in an isolate scope but not how to retrieve scope custom properties in template. I think the fix must be very simple but I just don’t figure out what’s wrong here <!doctype html> <html ng-app=”myApp”> <head> <script src=””></script> </head> <body> <div my-directive> </div> <script> angular.module(‘myApp’, []) .directive(‘myDirective’, function() { return { restrict: ‘A’, scope: { data.myProperty:”1234″ }, template:’Inside myDirective, isolate scope: {{ data.myProperty }}’ […]

Why doesn’t controller watch work when a directive transclude is set?

I’m reading Directives Explained chapter in ng-book The Complete Book on AngularJS. when it talks about transclude option in a directive, it says: If we use transclude, watching for model property changes from within the controller of a directive will not work properly. That is why best practice always recommends using the $watch service from within the link function. I understand what it means but I don’t know how this conclusion is reached. My guess […]

Directive not recognizing passed in variable

I have a a directive that is shown after an event is broadcast. In handling the event, I set the variable I need passed to the directive. But in the scope it is always undefined. I included the ‘profile’ variable that I am also using, and that is set correctly as part of the Calling controller. When the directive is rendered, it has profile populated but not vendor if, even though the “on” event has […]

One way binding doesn’t work in AngularJS with setInterval

AngularJS is the first version of Angular and is not relevant any more. But as I started learning Angular4, I wanted to start right from AngularJS so that I can explore the fundamentals and objectives of the framework. The below piece of code is to demonstrate one way data binding (changing the model re-renders the view) but unable to achieve it. <p>One-Way Data-Binding: {{place}}</p> is not updated every time there is change in the “$”. […]

without touching core controller call the extended controller and accessing the core controller function

i am having a core controller (function() { “use strict”; function FieldSettingsOverlay($scope, localizationService, formService, userService) { var vm = this; vm.changeValidationType = changeValidationType; vm.validationTypes = [{ “key”: “number”, “pattern”: “^[0-9]*$” }, { “key”: “url”, “pattern”: “https?://[a-zA-Z0-9-.]+.[a-zA-Z]{2,}” }]; function changeValidationType(selectedValidationType) { console.log(“Parent”) } } angular.module(“umbraco”).controller(“UmbracoForms.Overlays.FieldSettingsOverlay”, FieldSettingsOverlay); })(); from this parent controller i have an array called vm.validationTypes , this is currently having only 2 objects but i have to add 3 or 4 objects. so i […]

How prototypal inheritance works in AngularJS?

This example is from ng-book: The complete book on AngularJS. I don’t understand the result of the following example. <div ng-controller=”SomeController”> {{ someBareValue }} <button ng-click=”someAction()”>Communicate to child</button> <div ng-controller=”ChildController”> {{ someBareValue }} <button ng-click=”childAction()”>Communicate to parent</button> </div> </div> angular.module(‘myApp’, []) .controller(‘SomeController’, function($scope) { // anti-pattern, bare value $scope.someBareValue = ‘hello computer’; // set actions on $scope itself, this is okay $scope.someAction = function() { // sets {{ someBareValue }} inside SomeController and ChildController $scope.someBareValue […]

angularjs: accessing scope outside of ng-repeat

I have a link within a table that toggles open an accordion to reveal more details: <div class=”table-cell”> <a class=”flex collapsed” ng-class=”{‘accordion-toggle collapsed’:x.campaign.length>0}” ng-if=”x.campaign.length>0″ data-toggle=”collapse” href=”#{{x.sys_id}}” role=”button” aria-expanded=”false” aria-controls=”collapseDetails”></a> </div> Because this is within a table, I have to close the div in order for the additional details to appear in a new row, but this will stop giving me access to the scope of my ng-repeat. My current accordion code looks like this: <div […]

Understanding basics of controller in AngularJS

I’m still very basic with AngularJS (and programming in general honestly speaking. Having watched some videos online, I’m trying to understand the controller concept with the below example (e.g. passing an array and then iterating through it with ng-repeat). Have gone over this for the past hour and it works without the controller (e.g. with the array), but not when adding the array in a seperate script. Can anyone help me find my error in […]

optimize $scope.$digest() in Angular.js

I am trying to bind data from SQLServer to a Angularjs gantt chart using a procedure. The procedure takes 1-2secs to run but binding data to gantt is taking 120-150secs. This is happening because watchers are watching everything. I want to optimise $scope.$digest() such that watchers only watch elements which are necessary.I have attached a screenshot of profiler and added my current code, if anybody can provide any suggestions on how to reduce the time, […]

Next Page »