Maslow
Maslow

Reputation: 18746

Can I declare a variable in html?

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?

Upvotes: 7

Views: 23883

Answers (1)

Vinay
Vinay

Reputation: 2817

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

Upvotes: 5

Related Questions