Tips and Tricks in a world of Mix

Archive for 07/05/2014

Get scope from element

// Access whole scope
angular.element(myDomElement).scope();

// Access and change variable in scope
angular.element(myDomElement).scope().myVar = 5;
angular.element(myDomElement).scope().myArray.push(newItem);

// Update page to reflect changed variables
angular.element(myDomElement).scope().$apply();

Or if you’re using jQuery, this does the same thing…

$('#elementId').scope();
$('#elementId').scope().$apply();

Another easy way to access a DOM element from the console (as jm mentioned) is to click on it in the ‘elements’ tab, and it automatically gets stored as $0.

angular.element($0).scope();
Advertisements

New Vs Override

http://msdn2.microsoft.com/en-us/library/435f1dw2.aspx

The new modifier instructs the compiler to use your implementation instead of the base class implementation. Any code that is not referencing your class but the base class will use the base class implementation.

http://msdn2.microsoft.com/en-us/library/ebca9ah3.aspx

The override modifier may be used on virtual methods and must be used on abstract methods. This indicates for the compiler to use the last defined implementation of a method. Even if the method is called on a reference to the base class it will use the implementation overriding it.

http://social.msdn.microsoft.com/Forums/en-US/65e02299-300f-4b74-8f0a-679f490605f5/new-vs-override-?forum=Vsexpressvcs

Tag Cloud

%d bloggers like this: