2016-06-20 53 views
1

我正在用Orchard创建一个网站。使用AngularJS我正在从ASP.NET web API项目读取数据,并在我的网站上显示数据。我想要做的是显示页面的标题和元数据。在Orchard CMS动态地添加标题

我曾尝试本作的标题,但我得到了以下错误:

<div ng-controller="bookDetailController" data-ng-init="AddReaded()" ng-cloak> 
@{ 
    Layout.Title = {{book.Title}}; 
    } 

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0820: Cannot initialize an implicitly-typed local variable with an array initializer

+0

剃刀被编译在服务器端,所以它永远不会知道的变化在前端。 – devqon

回答

4

剃刀被编译在服务器端,所以它永远不会知道在前端的变化。你可以做的反而是创建一些指令是这样的:

angular.module("myApp", []) 
    .directive("pageTitle", function($document) { 
     return { 
      restrict: "A", 
      scope: { 
       pageTitle: "=", 
      }, 
      link: function(scope, elem) { 
       scope.$watch("pageTitle", function(newval) { 
        $document.title = newval; 
       }); 
      } 
     } 
    }); 

你将与添加标题:

<div 
    ng-controller="bookDetailController" 
    data-ng-init="AddReaded()" 
    ng-cloak 
    page-title="book.Title"> 
+1

你可以用'$ document.title = newval;'替换'angular.element(“title”).text(newval);'并注入'$ document'。 – Martin