ここに私の状況を例示するjsfiddleがあります。AngularJSの隔離されたスコープ/ディレクティブからのブロードキャストとコールコントローラ機能の受信?
まず、受け取ったディメンションでディレクティブを作成する正しい方法はありますか? その後、それぞれの指示は他の指示と隔離されるべきです。したがって、私はscope: {}
を使用しています。
..問題は...コントローラである関数を呼び出しているし、いずれかの放送を受信していないようだ私は、これは些細な問題であると確信しています..私は角に新しいです:)
<div ng-app="test">
<div ng-controller="containerCtrl">
<component ng-repeat='c in components' id="c.id" my-width="{{c.width}}" my-height="{{c.height}}">
</div>
</div>
コントローラ:
controller('containerCtrl', function ($scope) {
$scope.components = [{ id: "c1", width: 100, height: 100 },
{ id: "c2", width: 200, height: 100 },
{ id: "c3", width: 300, height: 100 }];
//in the actual controller I am using a socket provider and doing
//socket.forward([
// 'initPage',
// 'refreshPage'
// ], $scope);
//simulating it with a simple broadcast here..
$scope.$broadcast("onSomething", "");
$scope.doSomething = function (data) {
alert("doing something");
};
}).
は私がNGリピートを有する部品の数をロードするページを有します
とディレクティブ:
directive('component', function() {
var linkFn = function(scope, element, attrs) {
$(element).
resizable({
stop: function(event, ui) {
scope.emitSomething(attrs.id, ui.position);
}
});
scope.$on('onSomething', function(res) {
alert("onSomething!");
});
};
return {
restrict: 'E',
template: '<div class="ui-widget-content" style="width: {{width}}px; height: {{height}}px;"></div>',
replace: true,
scope: {
width:'@myWidth',
height:'@myHeight'
},
link : linkFn
};
});
パーフェクト、感謝を:)ここで働いてjsfiddle http://jsfiddle.net/dr9c6/6/タグで宣言された関数がコントローラ内部の関数であり、 '{data:}'を受け取る関数が指令スコープの関数であると言うのは正しいですか? –
fusio
@fusio、そうだね。 –
私は同様の問題を抱えています...コントローラーからのブロードキャストはディレクティブでイベントを発生させません...タイムアウトは時々これを解決しますが、必ずしもそうではありません...また、アプリケーションはかなり重く、事実、時間は常にそれを解決するだろう...それを行うための他の方法はありますか? – ackuser