简体   繁体   中英

Accessing ng-init inside $scope from razor file Model

I am having trouble finding a way to get the index off of a property on a razor file. I need to match the index of the table to the array that I have on scope.

I set a window value from my cshtml file to a scope property.

scope.discountFlightList = dealViewModel;

contains an array of items. 包含一组项目。 Most importantly deal.Fare

I need to access a certain index of the array each time the button located on the razor file is clicked. Below is the button that I am working with.

 <a href="" ng-click="openPriceChart()" class="btn-primary btn-sm pull-right hide-on-mobile"><span ng-bind-html="@deal.Fare | roundPrice | superCurrency: '@Language.Currency' : true"></span>* <i class="ha-icon fontIcon-angle-right"></i></a>

The index that I need is based on the fare value that I can see on ng-init which exists on each of NG-INIT见

<td ng-init="myInit('@deal.OriginText')"> // in dev tools = San Francisco, California

Ideally I would know what the index is when I click on the and set it to the array index. 并将其设置为数组索引时,我会知道索引是什么。 I was hoping this answer would do it How can I pass @Model to Angular ng-init

var testValue
$scope.myInit = function(name){
testValue = name;

}

But I am getting an empty string when I check on my debugger.

Since the razor file is using a foreach as opposed to the ng-repeat I don't see how I can use $index.

 @foreach (var deal in @Model.Deals.Take(Model.NumberOfFaresToDisplay ?? 6))
                {

Any help would be greatly appreciated.

Your answer is here: Getting index value on razor foreach

@{int i = 0;}
 @foreach(var myItem in Model.Members)
 {
     <span>@i</span>
     i++;
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM