An AngularJS directive for NVD3 re-usable charting library (based on D3).
Easily customize your charts via JSON API.
NVD3讓你可以透過directive來實現D3的繪圖效果: D,使用Angular需要圖表呈現可以考慮
app.directive('errSrc', function() {
return {
link: function(scope, element, attrs) {
scope.$watch(function() {
return attrs['ngSrc'];
}, function (value) {
if (!value) {
element.attr('src', attrs.errSrc);
}
});
element.bind('error', function() {
element.attr('src', attrs.errSrc);
});
}
}
})

app.config()app.run()app.controller()Run blocks - get executed after the injector is created and are used to kickstart the application. Only instances and constants can be injected into run blocks. This is to prevent further system configuration during application run time.Run blocks are the closest thing in Angular to the main method. A run block is the code which needs to run to kickstart the application. It is executed after all of the service have been configured and the injector has been created. Run blocks typically contain code which is hard to unit-test, and for this reason should be declared in isolated modules, so that they can be ignored in the unit-tests.
<div ng-app="myApp" ng-controller="myCtrl">
<div test1 test2> </div>
</div>
var myApp = angular.module('myApp', []);
myApp.factory('aProvider', function() {
console.log("factory");
});
myApp.directive("test1", function() {
console.log("directive setup");
return {
compile: function() {console.log("directive compile");}
}
});
myApp.directive("test2", function() {
return {
link: function() {console.log("directive link");}
}
});
myApp.run(function() {
console.log("app run");
});
myApp.config( function() {
console.log("app config");
});
myApp.controller('myCtrl', function($scope) {
console.log("app controller");
});
//get current user
String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();
String fakeUser = "IAMBIGD";
LOGGER.debug("currentUser:" + currentUser);
if (currentUser == null || !currentUser.equals(fakeUser)) {
// AuthenticationUtil.setCurrentUser(username);
//set impersonate
AuthenticationUtil.setFullyAuthenticatedUser(fakeUser);
}
app.directive('validFile',function(){
return {
require:'ngModel',
link:function(scope,el,attrs,ngModel){
//change event is fired when file is selected
el.bind('change',function(){
scope.$apply(function(){
ngModel.$setViewValue(el.val());
ngModel.$render();
});
});
}
}
});
Input is valid: {{myForm.userUpload.$valid}} Selected file: {{filename}}
//設定某個物件被選擇
ng-class="{true: 'table-row-selected', false: ''}[product.selected]"
//取得被選擇的使用者數量
$scope.getSelectedUsers = function() {
var selectedObjs = $filter("filter")($scope.userList, {
selected: true
})
return selectedObjs;
};
//html ng-repeat="folder in parentFolders.slice().reverse()
$location.path('/login');
$window.open('http://www.yahoo.com.tw');
$scope.userList.splice($index, 1);//移除使用者清單內的某一用戶
app.run(['$http', function($http) {
// The $http service will automatically add certain HTTP headers to all requests. These defaults can be fully configured by accessing the $httpProvider.defaults.headers configuration object, which currently contains this default configuration:
// $httpProvider.defaults.headers.common (headers that are common for all requests):
// Accept: application/json, text/plain, * / *
// $httpProvider.defaults.headers.post: (header defaults for POST requests)
// Content-Type: application/json
// $httpProvider.defaults.headers.put (header defaults for PUT requests)
// Content-Type: application/json
$http.defaults.headers.common['Content-Type'] = 'application/json';
}])
$scope.$watch('form', function(newVal, oldVal){
console.log('changed');
}, true);
app.run(['$templateCache',function($templateCache){
$templateCache.removeAll();
}]);
import urllib.request,os,hashlib; h = '7183a2d3e96f11eeadd761d777e62404' + 'e330c659d4bb41d3bdf022e94cab3cd0'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)
Filter and there are great explanation and example in StackOverflow Servlet-Filter wiki.needsAuthenticationmethod):@WebFilter("/*")
public class LoginFilter implements Filter {
@Override
public void init(FilterConfig config)
throws ServletException {
// If you have any in web.xml, then you could get them
// here by config.getInitParameter("name") and assign it as field.
}
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
HttpSession session = request.getSession(false);
String requestPath = httpServletRequest.getRequestURI();
if (needsAuthentication(requestPath) ||
session == null ||
session.getAttribute("user") == null) { // change "user" for the session attribute you have defined
response.sendRedirect(request.getContextPath() + "/login"); // No logged-in user found, so redirect to login page.
} else {
chain.doFilter(req, res); // Logged-in user found, so just continue request.
}
}
@Override
public void destroy() {
// If you have assigned any expensive resources as field of
// this Filter class, then you could clean/close them here.
}
//basic validation of pages that do not require authentication
private boolean needsAuthentication(String url) {
String[] validNonAuthenticationUrls =
{ "Login.jsp", "Register.jsp" };
for(String validUrl : validNonAuthenticationUrls) {
if (url.endsWith(validUrl)) {
return false;
}
}
return true;
}
}
app and then change the web filter to@WebFilter("/app/*")
needsAuthentication method from the filter.