-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2015-5-19 YouTube精彩Angular视频 Advanced Directives with Angular JS #31
Comments
$compile
下面Code中使用了$compile方法 angular.module("app").directive("editorInitializer", function($compile, $templateCache) {
return {
restrict: 'E',
templateUrl: '/templates/editor_initializer.html',
controller: function($scope) {
$scope.edit = function(row) {
$scope.$broadcast('edit', row);
};
},
link: function(scope, element, attributes) {
scope.$on('edit', function(e, row) {
var editor = $compile($templateCache.get("/templates/editor.html"))(scope);
$(editor).insertAfter(element.parents("tr"));
});
console.log('linked editorInitializer');
}
};
}); 更多细节可以参看 html compile |
$templateRequest
如何使用 angular.module("app", []).run(function($templateRequest) {
$templateRequest("/templates/editor.html");
}); |
$templateCache这个service就不多说了,大家可以自己参考文档, directive definition object (参考官方文档)
附赠一份angular directive生命周期 |
require other directives在directive definition object 中配置require,可以使一个指令,也可以是一个指令数组 注意这些语法:
|
directive communication ($scope.$broadcast, $scope.$on)指令之间的沟通,数据传递和交换,可以通过$broadcast 和 $emit 方法传递事件的方式进行沟通 |
Advanced Directives with Angular JS
视频: https://www.youtube.com/watch?v=Ty8XcASK9js
代码: https://github.com/davemo/advanced-directives-with-angular-js
The text was updated successfully, but these errors were encountered: