1

I am new to javascript and angular so,i would appreciate your help, before I start plz have a look at below two pictures-

enter image description here

After some time there is a change-

enter image description here

Now some attributes in below HTML code has same attribute, -

<input type="text"
       class="menuTitleField ng-pristine ng-untouched ng-valid ng-isolate-scope ng-valid-required" 
       ng-model="title" placeholder="Option Name" elastic-input=""
       ng-required="isRequired" focus-on="newChild" focus-if="canFocus"
       tabindex="0" required="required" style="min-width: 0px; width: 48px;">

For example, there are canFocus or title, in HTML and in above picture, so how can I get the value of canFocus, title using java script based on class name or tag name or event.target.id?

I think these values come from the sever, how can I get values of those attribute?

Plz, ask in comment for clarification, also edit the post for more precise question. thanks.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Mike
  • 269
  • 1
  • 8

3 Answers3

0

so how can I get the value of canFocus using java script

Use either:

$rootScope.canFocus

or

$scope.$root.canFocus
georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • does not work, ``$rootScope.canFocus VM87:1 Uncaught ReferenceError: $rootScope is not defined at :1:1 $scope.$root.canFocus VM92:1 Uncaught ReferenceError: $scope is not defined at :1:1`` also I asked about title attribute, how can I get that using class or tag ? ​ – Mike Oct 09 '19 at 15:23
0

To use $rootScope,$scope in your controllers, you need to import it then you can use variables to get values like

$scope.title
$scope.canFocus

if you want to use $rootScope just use this $rootScope.title $rootScope.canFocus

In your HTML title,canFocus should work with your code

  • I get below error when Irun your code in console - ``Uncaught ReferenceError: $rootScope is not defined at :1:1`` – Mike Oct 10 '19 at 06:30
  • Kindly use the below link to inject $rootScope and $scope.https://stackoverflow.com/questions/39951724/angularjs-uncaught-referenceerror-rootscope-is-not-defined – Veeresh Kumar Oct 10 '19 at 06:36
  • no idea how to modify the code in your link, could u plz include the comple code in answer? – Mike Oct 10 '19 at 07:12
-1

Angular has an angular way of doing almost everything. In this instance I would suggest researching property binding. For example with the placeholder property you can write:

<input [placeholder]="someVariable">

Then declare the someVariable in your component and what ever you set it to will be the placeholder and you can access it that way. The [] lets you set it to a variable in your component and will update the placeholder whenever you change it in your component. I would try experimenting with this to get an understanding for how it works.

Matt
  • 451
  • 2
  • 7