Angular2:来自表单标记外部的html中的引用表单

时间:2016-08-23 13:31:26

标签: html angular typescript

我正在尝试执行以下操作:

<?php
require_once __DIR__ . '/vendor/autoload.php';
session_start();

$client = new Google_Client();
$client->setAuthConfigFile('client_secrets.json');
$client->addScope(Google_Service_Drive::DRIVE);

if (isset($_GET['name']) && isset($_GET['type'])) {
//echo "We will download " . $_GET['name'] . " type " . $_GET['type'] . " with file id " . $_GET['fileid'];
    $fileId=$_GET['fileid'];
    if (isset($_SESSION['access_token']) && $_SESSION['access_token']) 
    {
        $client->setAccessToken($_SESSION['access_token']);
        $drive_service = new Google_Service_Drive($client);
        $content = $drive_service->files->get($fileId,  array(
            'alt' => 'media' ));
                $fileName = $_GET['name'];
        $headers = $content->getHeaders();

        foreach ($headers as $name => $values) {
            header($name . ': ' . implode(', ', $values));
        }
        header('Content-Disposition: attachment; filename="' . $fileName . '"');
        echo $content->getBody();
        //echo "<script>window.close();</script>";
        exit;
    }
    else
    {
        session_destroy();
        session_unset();
        header('Location: test.php'); 
    }

}
else
echo "incorrect files ";

基本上,使用表单状态(此处为<span *ngIf="heroForm?.dirty"> FOO </span> <form *ngIf="active" (ngSubmit)="onSubmit()" #heroForm="ngForm"> <div class="form-group"> <label for="name">Name</label> <input type="text" class="form-control" id="name" required [(ngModel)]="model.name" name="name" #name="ngModel"> </div> </form> )在表单标记之外显示范围。不幸的是,dirty从未显示过。有什么方法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

创建模型属性showFoo: boolean

并在某些表单事件上更改它,例如onChange

然后您的span看起来像

<span *ngIf="showFoo">FOO</span>