カスタムTypeScript
ディレクティブでコントローラのスコーププロパティにアクセスするにはどうすればよいですか?
例えば、私はscope.message
を記録したい次のスニペットで:アクセススコープfrom directives with typescript
/// <reference path="typings/angularjs/angular.d.ts" />
//module
module app {
var mainModule = angular.module('mainModule', []);
}
//controller
module app.testCtrl {
interface ITest {
message: string;
}
class TestCtrl implements ITest {
message: string = 'initial value'; // this is the value i want to access from my dierctive
}
angular.module('mainModule').controller('testCtrl', TestCtrl);
}
//directive
module app.directives {
export class MyDirective implements ng.IDirective {
restrict = 'A';
static instance(): ng.IDirective {
return new MyDirective;
}
link(scope: ng.IScope) {
//HOW DO I GET TO THE SCOPE PROPERTIES?
//console.log(scope.???);
}
}
angular.module('mainModule').directive('myDirective', MyDirective.instance);
}
PS - それは違いを作る場合、あなたがしているように私は、ビューの構文「のようなコントローラを」使用してい
説明してください**あなたがそれをしたい理由は、あなたがそれを悪用しているようです。あなたは 'console.log(scope.myControllerAsAlias.message);を実行することができます。しかし、「角度のある方法」は、コントローラから読み出す代わりにプロパティをディレクティブに渡すことです。 – devqon