Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I declare a variable in html?

Tags:

angularjs

Given

 <li>Document Printing - 
<a href="http://{{displaySandbox()}}/{{displayCase()}}/PrintingService/DocumentPrintingService.svc">
 <span ng-class="{true:'value',false:'invalid'}[(sandbox && validcase())==true]">http://<span class="sandbox">{{displaySandbox()}}</span>.companyname.com/<span class="case">{{displayCase()}}</span>/PrintingService/DocumentPrintingService.svc</span></a> 
<span ng-bind-html-unsafe="getUrl('/PrintingService/DocumentPrintingService.svc')">
</span>
</li>

I would like to declare something like to wrap this in

<div ng-var="subPath=/PrintingService/PrintingService.svc>

so that anything inside that scope would be able to say

    <li>Document Printing - 
<a href="http://{{displaySandbox()}}/{{displayCase()}}{{subPath}}">
 <span ng-class="{true:'value',false:'invalid'}[(sandbox && validcase())==true]">http://<span class="sandbox">{{displaySandbox()}}</span>.companyname.com/<span class="case">{{displayCase()}}</span>{{subPath}}</span></a> 
<span ng-bind-html-unsafe="getUrl(subPath)">
</span>
</li>

Is there a way to declare a scope (for a variable or 'constant' if you will), via angular.js in html?

like image 397
Maslow Avatar asked Aug 19 '13 16:08

Maslow


People also ask

How do you declare data in HTML?

Definition and UsageThe data-* attribute consist of two parts: The attribute name should not contain any uppercase letters, and must be at least one character long after the prefix "data-" The attribute value can be any string.

How do you declare and initiate variables in HTML?

You initialize a variable using the equals sign (=). You can read it as “the value of the variable on the left should be the data on the right”: var name = "Tom"; “Tom” is a string - a collection of letters.

Does HTML has variable?

The <var> HTML element represents the name of a variable in a mathematical expression or a programming context. It's typically presented using an italicized version of the current typeface, although that behavior is browser-dependent.

How do variables work in HTML?

The <var> element in HTML defines a text as a variable and can be used to define variables of a mathematical expression or variables of a piece of code. The text enclosed in the <var> element is normally displayed in italics. Note: The <var> element supports all global attributes and event attributes.


1 Answers

Using ng-init, you can initialize a value as below:

 <data ng-init="subPath= '/PrintingService/PrintingService.svc'"/>

However, it is better to use controller in such cases.

ng-init doc

like image 98
Vinay Avatar answered Sep 24 '22 18:09

Vinay