Angular variable only available in view, not controller

Tags: angularjs

I'm using Microsoft's adal.js for angular, which logs people in via a long and complicated auth chain and is only germane because when the login process is complete, adal makes the user's information available to views:


That works, but I don't know how.

I'm using controler-as syntax, so if I want to use $scope in my controllers, I have to specifically inject it, otherwise it's not available to said controller.

And $scope isn't being injected into the controller.

Bearing that in mind, how did the view get a hold of a $scope variable if the controller doesn't have $scope injected?


EDITED FOR CLARITY. I hope the question makes more sense now.

By : crowhill


It looks like the adal.js library manages a userInfo object for you on the rootScope. Unfortunately, this means that if you want to access it in a controller you'll have to inject a scope ($scope or $rootScope) into your controller in order to access it.

Views always and only have access to objects on scopes. In order to a view to have access to something it must be attached to the view's scope. I'm guessing the angular developers made the syntax {{ userInfo.userName }} instead of {{ $scope.userInfo.userName }} because of the above restriction (putting a $scope would be redundant)

If you want to avoid injecting the scope into your controller, you could create a factory that injects $rootScope and provides methods for accessing whatever you need.

This is somewhat complicated. The chess pieces are IMGs that can be clicked but empty chess squares are not represented by an element. You will have to determine a coordinate system and use move_to_element_with_offset(to_element, xoffset, yoffset) based off the board represented by <div id="chessboard_boardarea" ...> and the board labels A-H and 1-8. For move_to_element_with_offset(), the offsets are relative to the top-left corner of the element. So in this case, (0,0) is the top left corner of the chessboard.

The code below should click the white pawn at A2 and then click A3 which moves it. The board is 640px x 640px. Each square is 80px. The code is clicking in the middle of the square so:

  • A8 would be 40,40
  • A1 is 40,600
  • H8 is 600,40
  • H1 is 600,600

board = Driver.find_element_by_id("chessboard_boardarea")
action_chains = ActionChains(Driver)
action_chains.move_to_element_with_offset(board, 40, 520).click().perform() # A2
action_chains.move_to_element_with_offset(board, 40, 440).click().perform() # A3

You can determine what piece is represented by an element (IMG tag) by looking at the filename in the src attribute. For example, src="//" has the filename bn.png and is the black knight. Each image filename will be two letters. The first letter is the piece color which is either 'b' for black or 'w' for white. The second letter is the piece name, 'p' pawn, 'r' rook, 'n' knight, 'b' bishop, 'q' queen, and 'k' king. So, bn.png is 'b' for black and 'n' for knight... the black knight.

You can determine where pieces are by using the transform: translate(160px, 160px); portion of the style attribute of the IMG tags representing the different pieces. For example, transform: translate(160px, 160px); this element is at 160,160 which is C6 (the coords are the top-left of the square and each square is 80px).

By : JeffC

The key word that you're apparently missing is "epsilon." If you search on Python epsilon value then it returns a links to StackOverflow: Value for epsilon in Python near the top of the results in Google.

Obviously it helps if you understand how the term is associated with this concept.

This video can help you solving your question :)
By: admin