小编ott*_*der的帖子

如何用params做$ state.go()?

我已经完全初始化了$ stateProvider,我正在使用ui-sref来处理所有这些状态.效果很好.用户按下按钮,然后$ stateProvider进入编辑页面.

在这个页面上,我有一个$ http请求的表单:

 this.pushData = function (data) {
        $http.post('/data/' + $stateParams.dataId + '/otherdata', JSON.stringify({
            id: otherdata.id, 
            name: otherdata.name
        }), configAuth).then(
            function success(response) {
                var addedData = response.data;
                $.notify({message: addedData.name + " has been added"},{type:'success'});

                $state.go('roleInfo({roleId: $stateParams.roleId})');
            },
            function error(data) {
                console.log(data);
                $.notify({message: data.data.message},{type:'danger'});
            }
        );

    }
Run Code Online (Sandbox Code Playgroud)

如果一切正常,我想重定向到其他视图.但是这个:

$ state.go('roleInfo({roleId:$ stateParams.roleId})');

不起作用.我怎么能用params做$ state.go?

javascript routing angularjs angularjs-routing angular-ui-router

5
推荐指数
1
解决办法
2173
查看次数

从同一控制器内的函数调用函数

所以我试图调用functionanother function.并且它们都在同一个内部定义Controller.但到目前为止我尝试过的一切都是"funtion is not defined"最好的.如何正确地做这件事?

angular.module('App')

.controller('Controller', ['$http', '$scope', function($http, $scope) {

    this.getSomething1 = function() {};

    this.getSomething2 = function() {
        if (1 == 1) {
            getSomething1();
        }
    };
}]);
Run Code Online (Sandbox Code Playgroud)

ReferenceError:未定义getSomething1

javascript angularjs

3
推荐指数
2
解决办法
2万
查看次数

$ http请求.即使状态代码为401,响应也会成功

在我的Angular应用程序中,我有一个登录功能.但是当我发送错误的凭据并且响应带有状态401:Bad Credentials(甚至是response.status = 401)时,它仍然会成功.

所以我得到$ notify"我的拦截器中的成功登录然后是html错误页面.这令人困惑.我不知道我做了什么来制造这个混乱.

this.getTokenCustom = function (user) {
    $http.post('/login',
        JSON.stringify({username: user.username, password: user.password}))
        .then(
            function success(response) {
                localStorage.setItem('token', response.data.token);
                $.notify({message: "Success login"},{type:'success'});
                $state.go('roles');
            },
            function error(data) {
                console.log(data);
                $.notify({message: data.data.message},{type:'danger'});
            }
        );
};
Run Code Online (Sandbox Code Playgroud)

UPD

    this.getTokenCustom = function (user) {
    $http.post('/login',
        JSON.stringify({username: user.username, password: user.password}))
        .then(
            function success(response) {
                localStorage.setItem('token', response.data.token);
                $.notify({message: response.status + " Success login"},{type:'success'});
                $state.go('roles');
            },
            function error(data) {
                console.log(data);
                $.notify({message: data.data.message},{type:'danger'});
            }
        );
};
Run Code Online (Sandbox Code Playgroud)

屏幕

javascript http angularjs

0
推荐指数
1
解决办法
1071
查看次数