HTML template filled in server-side and updated client-side

后端 未结 4 764
攒了一身酷
攒了一身酷 2020-12-13 21:32

I have a webpage with dynamic content. Let\'s say it\'s a product page. When the user goes directly to example.com/product/123 I want to render my product templ

4条回答
  •  萌比男神i
    2020-12-13 22:20

    One option in AngularJS might be to use a directive that copies values rendered on the server into the model and have subsequent actions retrieve data via JavaScript.

    I've used the method described here in an ASP.NET WebForms application to pre-populate my model via hidden values from the server on the first request. Per the discussion this breaks from the Angular way but it is possible.

    Here is example of the html:

    
    

    JavaScript:

    var directiveModule = angular.module('customDirectives', []);
    
    directiveModule.directive('copyToModel', function ($parse) {
        return function (scope, element, attrs) {
            $parse(attrs.ngModel).assign(scope, JSON.parse(attrs.value));
        }
    });
    

提交回复
热议问题