在 Orchard CMS 中动态添加标题
Add title dynamically in Orchard CMS
我正在使用 Orchard 创建一个网站。使用 AngularJS,我从 ASP.NET 网络 API 项目读取数据,并在我的网站上显示数据。我想要做的是显示页面的标题和元数据。
我试过这个标题,但出现以下错误:
<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
Razor 是在服务器端编译的,所以它永远不会知道前端的变化。你可以做的是创建一些这样的指令:
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">
我正在使用 Orchard 创建一个网站。使用 AngularJS,我从 ASP.NET 网络 API 项目读取数据,并在我的网站上显示数据。我想要做的是显示页面的标题和元数据。
我试过这个标题,但出现以下错误:
<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
Razor 是在服务器端编译的,所以它永远不会知道前端的变化。你可以做的是创建一些这样的指令:
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">