私はAngularツアーとBootstrapツアーを使用していますが、オブジェクトを独自の領域に保持して、コントローラーに保存する必要がないようにしたいと考えています。オブジェクトをサービスに格納したいのですが、オブジェクトにも関数があります。それらが "eval()" 'dを取得すると、渡されたコントローラーではなく、サービスのスコープで起動します。具体的には、「$ scope」はサービスにはコンテキストがありませんが、コントローラーにはコンテキストがあります。
コードのサンプルを次に示します。
var returnedObj = {
steps: [
{
element: '#newProduct',
title: 'Create Products',
placement: 'bottom',
content: 'Create new products here'
}
],
backdrop: true,
//The function that I want to interact with the $scope through the controller
onShow: function (tour) {
$scope.tourDisabled = true;
$scope.filter.availability = 'all';
$scope.filter.gallery = 'Show All';
$scope.updateFilter();
}
};
JSON.stringifyとJSON.parseを試しましたが、関数では機能しません。これが行われるのは絶望的ですか?
$ rootScopeとは別に、これは可能ですか?
$scope
関数への引数として、または必要なコンテキストを渡す必要があります。
onShow: function (tour, $scope) {
$scope.tourDisabled = true;
$scope.filter.availability = 'all';
$scope.filter.gallery = 'Show All';
$scope.updateFilter();
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加