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.

3 Answers 3

0

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

Use either:

$rootScope.canFocus

or

$scope.$root.canFocus
Sign up to request clarification or add additional context in comments.

1 Comment

does not work, $rootScope.canFocus VM87:1 Uncaught ReferenceError: $rootScope is not defined at <anonymous>:1:1 $scope.$root.canFocus VM92:1 Uncaught ReferenceError: $scope is not defined at <anonymous>:1:1 also I asked about title attribute, how can I get that using class or tag ? ​
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

3 Comments

I get below error when Irun your code in console - Uncaught ReferenceError: $rootScope is not defined at <anonymous>:1:1
Kindly use the below link to inject $rootScope and $scope.stackoverflow.com/questions/39951724/…
no idea how to modify the code in your link, could u plz include the comple code in answer?
-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.

1 Comment

In addition to your answer, one can also use interpolation. <input placeholder="{{someVariable}}">

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.