ユーザーが値を入力し、別のコントローラがアクセスできるようにするためにこの値をサービスに送信する「検索」があります。しかし、私はそれをすることができない瞬間のために誰かが私を助けることができる場合、私は非常にusfull私は角度jを使用しています。ng-clickとサービスの間でパラメータを渡すAngular js
<input ng-model="search.searchText" type="text" class="form-control" placeholder="Search..." align="center">
をそしてここであなただけの合格しようとしている。
とJS
var app = angular.module('MainApp', [])
app.factory('Search', function($rootScope, $http){
var search = '';
\t function setSearch(bus){
\t \t search = bus;
\t }
\t function getSearch(){
\t \t return search;
\t }
\t return{
\t \t setSearch : setSearch,
\t \t getSearch: getSearch
\t };
\t //return myFactory;
\t /*
\t $scope.Search = function() {
\t \t return {
\t \t \t getDoctor: function() {
\t \t \t \t return $http.get('api/doctor' + $scope.search.searchText).then(function (response) {
\t \t \t \t \t orders = response.data;
\t \t \t \t \t $rootScope.$broadcast('handleSharedOrders', orders);
\t \t \t \t \t return orders;
\t \t \t \t })
\t \t \t }
\t \t };
\t }*/
});
app.controller('mainController', function ($scope, $http, Search) {
\t $scope.loadList = function() {
\t \t location.href = "doctors";
\t };
$scope.search.searchText = Search.getSearch();
\t $scope.Search = function(bus) {
\t \t console.log(bus);
\t \t Search.setSearch(bus);
\t }
\t $scope.doctors = {};
\t $http.get('/api/doctor').success(function (data) {
\t \t $scope.doctors = data;
\t })
\t \t .error(function (data) {
\t \t \t console.log('Error: ' + data);
\t \t });
\t /*
\t $http.get('/api/doctor/' + specialty).success(function (data) {
\t \t $scope.doctorsSpecialty = data;
\t })
\t \t .error(function (data) {
\t \t \t console.log('Error: ' + data);
\t \t });
*/
});
<!DOCTYPE html>
<html ng-app="MainApp">
<head lang="en">
\t <meta charset="UTF-8">
\t <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
\t <!-- Cargamos app -->
\t <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>
\t <script src="../Controllers/core.js"></script>
\t <title></title>
</head>
<body ng-controller="mainController">
<div align="center">
\t <img src="../img/logo.jpg" >
</div>
<div class="container">
\t <div class="row">
\t \t <div class="col-md-4 col-md-offset-4">
\t \t \t <div class="login-panel panel panel-default" >
\t \t \t \t <div class="panel-heading" >
\t \t \t \t \t <h3 class="panel-title">Search Doctors</h3>
\t \t \t \t </div>
\t \t \t \t <div class="panel-body" >
\t \t \t \t \t <form role="form" >
\t \t \t \t \t \t <fieldset>
\t \t \t \t \t \t \t <div class="form-group" name="myForm" >
\t \t \t \t \t \t \t \t <input ng-model="search.searchText" type="text" class="form-control" placeholder="Search..." align="center">
\t \t \t \t \t \t \t </div>
\t \t \t \t \t \t \t <button class="btn btn-default" type="button" align="center" ng-click="Search(searchText)">
\t \t \t \t \t \t \t \t <b align="center">Search</b>
\t \t \t \t \t \t \t </button>
\t \t \t \t \t \t \t <!-- Change this to a button or input when using this as a form -->
\t \t \t \t \t \t </fieldset>
\t \t \t \t \t </form>
\t \t \t \t </div>
\t \t \t </div>
\t \t \t <div class="panel-heading" STYLE="background-color: #a7b5ce">
\t \t \t \t <h3 class="panel-title">List of Doctors</h3>
\t \t \t </div>
\t \t \t <div class="panel-body" >
\t \t \t \t <form role="form">
\t \t \t \t \t <fieldset>
\t \t \t \t \t \t <div class="form-group" name="myForm" >
\t \t \t \t \t \t \t <button class="btn btn-default" type="button" align="center" href=doctors ng-click="loadList()">
\t \t \t \t \t \t \t \t <b>List of Doctors</b>
\t \t \t \t \t \t \t </button>
\t \t \t \t \t \t </div>
\t \t \t \t \t \t <!-- Change this to a button or input when using this as a form -->
\t \t \t \t \t </fieldset>
\t \t \t \t </form>
\t \t \t </div>
\t \t </div>
\t </div>
</div>
</body>
</html>
あなたがsearch.searchText
を定義している私にここで