2017-11-23 19 views
0

$ scope.abc()のデータを実際の関数に渡そうとしています。

[機能]

function sweetAlertCtrl($scope, SweetAlert, $state) { 
    $scope.demo1 = function() { 
     SweetAlert.swal({ 
      title: "Good job!", 
      text: "You clicked the button!", 
      type: "success" 
     }, 
     function ($state) { 
      $state.go('pjt.detailed', {id: $scope.id}) // This is where the data from $scope is received. 
     }); 
    } 
} 

を[$スコープからのデータ]

$scope.demo1($scope.id); 

は、どのように私は()関数をDEMO1する$ scope.idを渡すことができますか? $州を正しい場所に置くことさえできましたか?私はこれに新しいです、これは本当に混乱しています:)

私は何をすべきかアドバイスしてください。

ありがとうございます!あなたのcontroller/service/factoryの/ etc内の他の依存関係の中で

$scope.demo1 = function (id) { 
    SweetAlert.swal({ 
     title: "Good job!", 
     text: "You clicked the button!", 
     type: "success" 
    }, 
    function ($state) { 
     $state.go('pjt.detailed', {id: id}) 
    }); 
} 

答えて

1

パス

app.service('myService', function($scope, $state) { 
    // Now you can use $state in all your functions here 
}) 
2

入れ$state、このような:関数$ scope.demo1へのパラメータとして$のscope.idで

+1

ありがとうございます。はい、あなたは正しいです。私はその部分を欠いていた。行動を取るのは簡単でしたが、問題の内容を見つけるのは難しかったです。 :) どうもありがとうございます! –

+0

答えとしてもう少し多くのコードを入力すると便利な場合があります。 – scipper

関連する問題