注入参数UI-Router的儿童



我想将我的孩子视为网络。

我已经声明了我的配置:

var states = [
    {
        name: 'application',
        url: '/application',
        component: 'application'
    },
    {
        name: 'application.detail',
        url: '/:id',
        component: 'applicationInfo'
    }
];
// Loop over the state definitions and register them
states.forEach(function(state) {
    $stateProvider.state(state);
});

我有一个按钮,哪个尝试?注入视图

        <button type="button" ui-sref="application.detail({id: application.id})" class="btn btn-sm btn-danger">
            <i class="glyphicon glyphicon-info-sign">
            </i>
        </button>

和一个组件:

angular.module('crudModule').component('applicationInfo', {
template: '<h1>hellllooooooooo</h1>',
controller: function($stateParams) {
    }
});

编辑:

应用程序组件:

angular.module('crudModule').component('application', {
templateUrl: 'applicationModule.html',
controller: function($http, $scope, httpService, $cookies, $log, $document, $dialogs) {
    httpService.httpGetRequest('http://localhost:8080/applications').then(function success(response) {
        $scope.applications = response.data;
        $scope.displayedApplications = [].concat($scope.applications);
    })
    $scope.deleteApplication = function (id) {
        $http({
            method: 'DELETE',
            url: "http://localhost:8080/application/" + id,
        }).then(function success(response) {
                httpService.httpGetRequest('http://localhost:8080/applications').then(function success(response) {
                $scope.applications = response.data;
                $scope.displayedApplications = [].concat($scope.applications);
            })})
    };
}

});

ApplicationModule HTML:

    <table st-table="applications" st-safe-src="displayedApplications" class="table table-striped" style="width: auto;">
    <thead>
    <tr>
        <th st-sort='id'>Id</th>
        <th st-sort='name'>Name</th>
    </thead>
    <tbody>
    <tr ng-repeat="application in applications">
        <td>{{application.id}}</td>
        <td>{{application.name}}</td>
        <td>More info
            <button type="button" ui-sref="application.detail({id: application.id})" class="btn btn-sm btn-danger">
                <i class="glyphicon glyphicon-info-sign">
                </i>
            </button>
        </td>
    </tr>
    </tbody>
</table>
<div class="form-group">
    <button class="btn btn-primary" ui-sref="addApplication">Add new</button>
</div>
<div class="form-group">
    <button type="button" class="btn btn-default" ng-click="open()">Open me!</button>
</div>

我包括应用程序模块:当我单击按钮时,我的URL更改为/application/(编号),但视图不会更改。

您需要在应用程序组件中具有:

<ui-view></ui-view>

因为路由器搜索此内容以放置内容。

检查以下内容:https://ui-router.github.io/ng1/tutorial/hellogalaxy

最新更新