2016-05-24 11 views
2

私はistevenのmultiselect指令を使用している初心者です。なぜ私のangularjsマルチセレクションインターフェイスが機能しないのですか?

私はtest caseを書きましたが、それはルートフォルダのHTMLからうまく機能しますが、my appに組み込んだときに、どのドロップダウンも表示されません。

console.logエラーメッセージはありません。

HTMLとコントローラを同じファイルにバンドルしました。 "myApp.controller( 'MainCtrl'、function($ scope、$ http))"は、 "var myApp = angular.module(" myApp "、[" isteven-multi-select "])が実行されても実行されません。 );角度はJSONにinsiting保たれているため、」

<html data-ng-app="myApp" id="myApp" lang="en"> 
    <head> 
     <title>Writer's Tryst - Enablers Form</title> 
     <link type="text/css" href="css/enablers.css" rel="stylesheet" /> 
     <link rel="stylesheet" href="css/isteven-multi-select.css"> 
    </head> 
    <body data-ng-controller="MainCtrl"> 
     <div class="container center_div"> 
      <!--<form id="form-writers" class="form-horizontal well">--> 
      <img id="img-enablers" src="#" alt="images" /> 
      <form id = "form-enablers" class="form-horizontal well"> 
       <h1>Enablers</h1> 

       <label for="work-type" class="fixed50">Type:</label> 
       <p id="work-type" 
        data-isteven-multi-select 
        data-input-model="worktype" 
        data-output-model="outputWorktype" 
        data-button-label="icon name" 
        data-item-label="icon name" 
        data-tick-property="ticked" 
       ></p> 
       <label for="form-type" class="fixed50">Form:</label> 
       <p id="form-type" 
        data-isteven-multi-select 
        data-input-model="formtype" 
        data-output-model="outputFormtype" 
        data-button-label="name" 
        data-item-label="name" 
        data-tick-property="ticked" 
       ></p> 
       <p>For an explanation of the genres s hown here, see <a target="_blank" href="https://en.wikipedia.org/wiki/List_of_genres">List of genres</a><br/></p> 
       <label for="genres" class="fixed50">Genres:</label> 
       <p id="genres" 
        data-isteven-multi-select 
        data-input-model="genres" 
        data-output-model="outputGenres" 
        data-button-label="name" 
        data-item-label="name" 
        data-tick-property="ticked" 
       ></p> 
       <label for="accepted-media" class="fixed50">Accepted Media:</label> 
       <p id="accepted-media" 
        data-isteven-multi-select 
        data-input-model="acceptedMedia" 
        data-output-model="outputMedia" 
        data-button-label="icon name" 
        data-item-label="icon name" 
        data-tick-property="ticked" 
       ></p> 
       <p> <label for="special-instructions" class="fixed50">Special Instructions</label> 
        <textarea id ="special-instructions" name="special-instructions"> 
        </textarea> 
       </p> 
       <p>For a limited time, enablers can use this site for <span style="color: #f00; font-weight:bold">FREE</span>. We reserve the right to change this policy without notice.</p> 
       <div id="recaptcha-elements"></div> 
       <div class="form-group"> 
        <button type="submit" id="enablers-search" class="btn btn-default glyphicon glyphicon-search"> Search</button> 
       </div> 
       <input id="userid" name="userid" type="hidden" /> 
      </form> 
     </div> 
     <form id="writers-list"> 
      <p>To request a manuscript, click the checkbox beneath the thumbs-up icon.</p> 
      <div id="table-list"></div> 
     </form> 
     <script src="js/isteven-multi-select.js"></script> 
     <script src="js/enablers.js"></script> 
     <script src="js/recaptcha.js"></script> 
     <script> 
     var myApp = angular.module("myApp", [ "isteven-multi-select" ]); 

     myApp.controller('MainCtrl', function ($scope, $http) { 
      alert("got here"); 
      $scope.worktype = [ 
       { icon: "<img src=img/icons/smile-mask.png />", name: "Fiction", ticked: false }, 
       { icon: "<img src=img/icons/frown-mask.png />", name: "Non-Fiction", ticked: false } 
      ]; 
      $scope.formtype = []; 
      var data = {}; 
      data.action = 'multiselect-forms'; 
      ajax('post', 'php/enablers.php', data, formsSuccess, 'Error retrieving multiselect forms data: '); 
      function formsSuccess(data) { 
       console.log(data); 
       $scope.formtype = eval(data); 
      } 
      $scope.genres = []; 

      data.action = 'multiselect-genres'; 
      ajax('post', 'php/enablers.php', data, genresSuccess, 'Error retrieving multiselect forms data: '); 
      function genresSuccess(data) { 
       console.log(data); 
       $scope.genres = eval(data); 
      } 
      $scope.acceptedMedia = [ 
       { icon: "<img src=img/icons/email.png />", name: "Mail", ticked: false }, 
       { icon: "<img src=img/icons/pdf.png />", name: "PDF File", ticked: false } 
      ]; 

    /* 
    $http({ 
    method: "POST", 
    url: "php/enablers.php", 
    params: data, 
    contentType: 'text' 
    }).then(function mySucces(response) { 
    console.log(response.data); 
    //  $scope.formtype = response.data; 
    }, function myError(response) { 
    $scope.FORMTYPE = response.statusText; 
    }); 
    */ 
}) 

     </script> 
    </body>       s 
</html> 

お知らせをして、私はPHPのinteraceからのヘッダがtext/plainのと同様に、HTTPコールspecifiingのコンテンツタイプを指定したにも関わらず、jQueryのAjaxの使用に頼っcontentType = 'テキスト'

PHP

<?php 
require_once 'dbconnect.php'; 

function isEmpty($str) { 
    return strlen(trim($str)) == 0; 
} 
function buildInStmt($array) 
{ 
    if (is_array($array)) { 
     $in = implode(',', $array); 
    } else $in = "'" . $array . "'"; 
    return $in; 
} 
function multiselectGenres() 
{ 
    try { 

     $dbh = connect2DB(); 
     $stmt = $dbh->prepare("SELECT ID, Genre FROM Genres ORDER BY Genre"); 
     if (!$stmt->execute()) { 
      echo "\nPDOStatement::errorCode(): "; 
      print $stmt->errorCode(); 

      print_r($dbh->errorInfo()); 
     } else { 
      $select = "["; 
      $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); 
      foreach ($rows as $row) { 
       $genre = $row['Genre']; 
       $id = $row["ID"]; 
       $select .= "{"; 
       $select .= 'name: '; 
       $select .= '"' . $genre . '",'; 
       $select .= 'ticked: false},'; 
      } 
      $select = substr($select, 0, -1) . "]"; 
     } 
     header("Content-Type: text/plain"); 
     echo $select; 
    } catch (PDOException $e) { 
     echo 'Connection failed: ' . $e->getMessage(); 
    }   
} 
function multiselectForms() { 
    try { 
     $dbh = connect2DB(); 
     $stmt = $dbh->prepare("SELECT ID, Form FROM Forms ORDER BY Form"); 
     $stmt->execute(); 
     $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); 
     $select = "["; 
     foreach ($rows as $row) { 
      $id = $row['ID']; 
      $form = $row['Form']; 
      $select .= "{"; 
      $select .= 'name: '; 
      $select .= '"' . $form . '",'; 
      $select .= 'ticked: false},'; 
     } 
     $select = substr($select, 0, -1) . "]"; 
     header("Content-Type: text/plain"); 
     echo $select; 
    } catch (PDOException $e) { 
     echo 'Database error: ' . $e->getMessage(); 
    } catch (Exception $e) { 
     echo 'General failure: ' . $e->getMessage(); 
    }  
} 

function search() { 
    try{ 
     /* 
     if (!isset($_REQUEST["work-type"]) || isEmpty($_REQUEST["work-type"])) 
      throw new Exception('You must select a type of work.'); 
     else { 
      $worktype = filter_var(trim($_REQUEST["work-type"]), FILTER_SANITIZE_STRING); 
      $worktype = htmlspecialchars_decode($worktype, ENT_QUOTES); 
     } 
     */ 
     manageEnablerData(); 
     if (!isset($_REQUEST["userid"]) || isEmpty($_REQUEST["userid"])) { 
      throw new Exception('A user-id must be supplied.');  
     } 
     $userid = $_REQUEST["userid"]; 
     if (!isset($_REQUEST["form-type"]) || empty($_REQUEST["form-type"])) { 
      throw new Exception('You must select a form type.');  
     } 
     $forms = buildInStmt($_REQUEST["form-type"]); 

     if (!isset($_REQUEST["genre"]) || empty($_REQUEST["genre"])) { 
      throw new Exception('You must select a genre.');  
     } 
     $genres = buildInStmt($_REQUEST["genre"]); 
     /* 
     if (!isset($_REQUEST["sub-genre"]) || isEmpty($_REQUEST["sub-genre"])) 
      throw new Exception('You must select a sub-genre.');  
     else { 
      $subgenre = filter_var(trim($_REQUEST["sub-genre"]), FILTER_SANITIZE_STRING); 
      $subgenre = htmlspecialchars_decode($subgenre, ENT_QUOTES); 
     } 
     */ 
     $dbh = connect2DB(); 
     $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
     $stmt = $dbh->prepare("SELECT a.ID, a.Email, a.Name, w.Title, w.Filename FROM Writers w JOIN Accounts a ON a.ID = w.fkAccounts WHERE a.ID = :userid AND FormType IN($forms) AND Genre IN($genres)"); 
     $stmt->bindParam(':userid', $userid, PDO::PARAM_INT); 
     $stmt->execute(); 
     $rows = $stmt->fetchAll(); 
     $table = '<table><tr><th>Author</th><th>Title</th><th>Synopsis</th><th><img src="img/Thumb-up-icon.png" width="32" alt="thumbs-up" </th></tr>'; 
     foreach ($rows as $row) { 
      $table .= "<tr><td>" . $row['Name'] . "</td><td>" . $row['Title'] . "</td><td>" . "<a href='uploads/" . $row['Filename'] . "' target=_blank>synposis file</a>" . "</td><td><input type='checkbox' id='request-manuscript' name='request-manuscript'" . "</td><td class='hidden'>" . $row['ID'] . "</td><td class='hidden'>" . $row['Email'] . "</td></tr>"; 
     } 
     $table .= "</table>"; 
     echo $table; 

    } catch (PDOException $e) { 
     echo 'Database error: ' . $e->getMessage(); 
    } catch (Exception $e) { 
     echo 'General error: ' . $e->getMessage(); 
    }  

} 
function manageEnablerData() 
{ $si = ""; //special-instructions 
    if (isset($_REQUEST["special-instructions"]) && !isEmpty($_REQUEST["special-instructions"])) { 
     $si = filter_var(trim($_REQUEST["special-instructions"]), FILTER_SANITIZE_STRING); 
     $si = htmlspecialchars_decode($si, ENT_QUOTES); 
    } 

    if (!isset($_REQUEST["userid"]) || isEmpty($_REQUEST["userid"])) { 
     throw new Exception('A user-id must be supplied.');  
    } 
    $userid = $_REQUEST["userid"]; 
    /*  
    if (!isset($_REQUEST["accepted-media"]) || empty($_REQUEST["accepted-media"])) { 
     throw new Exception('An accepted media must be entered.');  
    } 
    $acceptedMedia = buildInStmt($_REQUEST["accepted-media"]); 
    */ 
    $dbh = connect2DB(); 
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
    $stmt = $dbh->prepare("INSERT Enablers(fkAccounts, SpecialInstructions) VALUES(:fka, :si) ON DUPLICATE KEY UPDATE fkAccounts=VALUES(fkAccounts), SpecialInstructions=VALUES(SpecialInstructions)"); 
    $stmt->bindParam(':fka', $userid, PDO::PARAM_INT); 
    $stmt->bindParam(':si', $si, PDO::PARAM_STR); 
    $stmt->execute(); 
    //need to handle AcceptedMedia 
} 
//var_dump($_REQUEST);exit(); 
if (!isset($_REQUEST['action']) || isEmpty($_REQUEST['action'])) 
    throw new Exception('Programmer error: action not posted.'); 
else { 
    $action = $_REQUEST['action']; 
    switch($action) { 
    case 'search': 
     search(); 
     break; 
    case 'select': 
     select(); 
     break; 
    case 'multiselect-genres': 
     multiselectGenres(); 
     break; 
    case 'multiselect-forms': 
     multiselectForms(); 
     break; 
    default: 
     throw new Exception("Unknown action: " . $action); 
     break; 
    } 
} 

?> 

私がdownvoteに値すると決めたら、間違いから学ぶかもしれないように私が間違っていることを理解するのを助けてください。

+0

あなたのアプリでは、あなたの 'MainCtrl'は決して呼ばれないようです。それは...ですか? –

+0

それは困惑しているものです。 –

答えて

1

1.なぜ機能しない:

A)。 のテストケースでは、<body data-ng-controller="MainCtrl">をあなたのhtmlに入れて、これはMainCtrlという機能を呼び出します。

b)。あなたのアプリでは、あなたはまた、MainCtrlを持っていませんが、あなたのどちらもHTMLも$routeProvider.when

ソリューションから呼び出す:

1)。最も簡単な方法は、あなたのアプリで<body data-ng-controller="MainCtrl">をテストケースと同じにすることです。

2)。 MainCtrlのコードをenablersControllerに入れてください。#/enablersのこの入力モデルを選択してください。

両方とも推測ですが、問題があれば教えてください。

+0

私はあなたのソリューションをアプリに組み込みました。js(あなたは "myApp"からアクセス可能ですが、コードの例を提供することができれば助けになるでしょう。 –

+0

あなたはpages.jsのenablersControllerを参照していますか?もしそうなら、それは動作しませんでした私は、ページの$スコープがメインのindex.htmlにあり、enablers.htmlの$ scopeではないと思います。 –

+0

$ routeProvider.whenからどのように呼び出すのですか?親コントローラを投稿しました。イネーブラーから? –

関連する問題