点击按钮没反应啊
点击没有增加啊,
$emit 和 $broadcast 咋用啊?没找到相关文档,
老师 那个 scope2.js 里面的代码能分享一下吗
点击没有增加啊,
$emit 和 $broadcast 咋用啊?没找到相关文档,
老师 那个 scope2.js 里面的代码能分享一下吗
2017-03-17
/**
* Created by Administrator on 2017/3/21.
*/
var booksStoreModule = angular.module('my.new.module',[]);
booksStoreModule.service('Book',['$rootScope',function ($rootScope) {
var service = {
books:[
{title:'测试',author:'周斌'},
{title:'angular',author:'周斌'}
],
addBook:function (book) {//传入对象,对象包括书名和作者
service.books.push(book);
$rootScope.$broadcast('books.update');
}
}
return service;
}]);
booksStoreModule.controller('book.list',['$scope','Book',function (scope,Book) {
scope.$on('books.update',function (event) {
scope.books = Book.books;
scope.$apply();
});
scope.books = Book.books;
}]);
booksStoreModule.directive('addBookButton',['Book',function (Book) {
return{
restrict:'A',
link:function (scope,element,attrs) {
element.bind('click',function () {
Book.addBook({title:'643534',author:'怎么这么难'});
});
}
}
}]);
//应该是没问题
举报