在控制器中:
$scope.height = "height:100px;";
$scope.color = "red"
在HTML中:
<div class="capsule" ng-style="{'height': height; 'background': color}"></div>
我怎样才能让它发挥作用?
答案 0 :(得分:2)
你有一个半结肠&#39 ;;&#39;在样式之间,ng-style期望一个对象(以逗号分隔)。以下代码应该有效 -
<?php
$newsPieces = scandir("posts");
for ($i = 2; $i < count($newsPieces) and $i < 12; $i++) {
$titlefile = fopen("posts/" . $newsPieces[$i] . "/title.txt", "r") or die("Unable to open file!");
$textfile = fopen("posts/" . $newsPieces[$i] . "/text.txt", "r") or die("Unable to open file!");
$fullElement = "<div class='newsPiece'><div class='newsImageHolder'><img class='newsImage' src='posts/" . $newsPieces[$i] . "/image.jpg'></div><div class='newsContent'><h1 class='newsTitle'>" . fread($titlefile, filesize("posts/" . $newsPieces[$i] . "/title.txt")) . "</h1><p class='newsText'>" . fread($textfile, filesize("posts/" . $newsPieces[$i] . "/text.txt")) . "</p><a class='newsLink' href='post?post=" . urlencode($newsPieces[$i]) . "'>Continue Reading</a></div></div>";
echo $fullElement;
fclose($titlefile);
fclose($textfile);
}
?>
答案 1 :(得分:1)
您正在寻找使用ng-style
指令,该指令采用描述样式名称及其值的对象,如下所示:
<div class="capsule" ng-style="{'height': height}"></div>