AngularJS - generating a view from a .NET controller is done only once

I have an MVC.NET application with AngularJS. In my route provider, I use mvc controllers to return views as follows:

   .when('/Units', {
        templateUrl: 'Unit/Units'
    })
    .when('/UnitsDetail', {
        templateUrl: 'Unit/UnitsDetail'
    })

And my .NET UnitController has the following methods:

 [Authorize]
    public ActionResult Units()
    {
        return View();
    }

    [Authorize]
    public ActionResult UnitsDetail()
    {
        ViewBag.reference = Guid.NewGuid().ToString().Substring(0, 6);
        return View();
    }

To represent UnitsDetail, I need a link that is created in the UnitsDetail () method.

The problem occurs when I switch from Units to UnitsDetail several times. The UnitsDetail () method is called for the first time, and thus a link is created, but if I go back to the units and earn UnitsDetail again, the method will not be called, and the link will be the same. I need to generate one link every time.

, JS AJAX Angular , , Angular UnitsDetail() , "#/UnitsDetail".

!

+4
1

angular .

.

Angular , HTML , {{dynamicScopeVariable}}. angular . .

.

2 . , # 2.

№ 1

angular, fooobar.com/questions/381216/...

, angular HTML ACTION , .

angualar, . . ASP.NET MVC . , , MVC , .

# 2

angialar, GUID . .. .

 ViewBag.reference = Guid.NewGuid().ToString().Substring(0, 6);

WebAPI, ( ). angular GUID ur VIEW.

, GUID, Javascript. , . 1 2.

: , 2, 1 .

2: ,

 $templateCache.remove("<Element Name>");

$cacheFactory.remove("Name")

factory : https://docs.angularjs.org/api/ng/service/ $cacheFactory

, , , factory , .

+1

Source: https://habr.com/ru/post/1617584/


All Articles