AngularJS通过wamp / json进行搜索

时间:2018-06-12 22:54:35

标签: angularjs json wamp ngroute

我制作了一些网站,我添加了路由(我将在下面的代码中显示)

当我点击某个类别时(例如' web开发')我想显示该类别的书籍,但我不知道如何范围该类别名称,我应该在第一行输入什么json文件?也许我困惑了你,我很抱歉。我希望有人可以帮助我。

HTML:

<div class="aside">
    <h3 ng-repeat="category in categories" class="aside-content">
        <a href={{"#category/"+category.name}}>{{category.name}}</a>
    </h3>
</div>

角:

myApp.config(function ($routeProvider) {
 $routeProvider
     .when('/category/:name', {
     templateUrl: 'pages/category.html',
     controller: 'catCtrl'
 }) });

WAMP / JSON:

$app->get('/categories', function (Request $request, Response $response, array $args) {
// Sample log message
$arr = [
    [
        "id"=> 1,
        "name"=> 'Web development'
        ],
    [
        "id"=> 2,
        "name"=> 'Programming'
        ],
    [
        "id"=> 3,
        "name"=> 'Game Programming'
        ],
    [
        "id"=> 4,
        "name"=> 'Operating Systems'
        ],
    [
        "id"=> 5,
        "name"=> 'Database'
        ],
    [
        "id"=> 6,
        "name"=> 'Graphics & Design'
        ],
    [
        "id"=> 7,
        "name"=> 'Administration'
        ],
    [
        "id"=> 8,
        "name"=> 'Enterprise'
        ],

];

$response->getBody()->write(json_encode($arr,true));

// Render index view
return $response->withHeader('Access-Control-Allow-Origin', '*')
        ->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization')
        ->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');  });

0 个答案:

没有答案