我在项目中使用基于状态的路由(Angular UI Router v0.2.7)并寻找从给定URL字符串获取当前状态(名称)的方法.
就像是:
$state.get([urlString]) returns stateName:String or state:Object
Run Code Online (Sandbox Code Playgroud)
我需要此方法来检查给定URL是否存在状态,因为并非所有URL都映射到项目中的状态.使用Play Framework作为后端,某些URL(例如,登录表单)未映射到状态,因为它们使用不同的模板,然后是我的应用程序的Angular(主要)部分.对于那些"无角度"页面(即,未被状态覆盖),我会进行重新加载.要识别状态未涵盖的URL,我需要上述方法.计划像这样做:
$rootScope.$watch(function() { return $location.path(); }, function(newUrl, oldUrl) {
if(newUrl !== oldUrl) {
if (!$state.get(newUrl)) {
$window.location.assign(newValue);
}
}
}
Run Code Online (Sandbox Code Playgroud)
已经检查过文件但没有这样的方法.
有任何想法吗?
根据https://developers.google.com/webmasters/ajax-crawling/docs/html-snapshot,使用HtmlUnit(2.13)我尝试使用AngularJS(1.2.1)为网页创建快照.
我的Java代码是:
WebClient webClient = new WebClient();
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.setCssErrorHandler(new SilentCssErrorHandler());
webClient.getOptions().setCssEnabled(true);
webClient.getOptions().setRedirectEnabled(false);
webClient.getOptions().setAppletEnabled(false);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setPopupBlockerEnabled(true);
webClient.getOptions().setTimeout(10000);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(true);
webClient.getOptions().setThrowExceptionOnScriptError(true);
webClient.getOptions().setPrintContentOnFailingStatusCode(true);
HtmlPage page = webClient.getPage(new WebRequest(new URL("..."), HttpMethod.GET));
webClient.waitForBackgroundJavaScript(5000);
String result = page.asXml();
Run Code Online (Sandbox Code Playgroud)
虽然webClient.getPage(...)
不会抛出任何异常,但结果字符串仍然包含"未评估的角度表达式",例如
<div>
{{name}}
</div>
Run Code Online (Sandbox Code Playgroud)
我知道http://htmlunit.10904.n7.nabble.com/htmlunit-to-scrape-angularjs-td29931.html#a30075,但那里给出的推荐也不起作用.
当然,相同的GET请求在所有当前浏览器中都没有例外.
有任何想法/经验如何让HtmlUnit与AngularJS一起使用?
更新:
我创建了一个HTMLUnit 错误报告.
目前,我将我的实现切换到了PhantomJS.也许这段代码片段可以帮助其他人解决类似的问题:
System.setProperty("phantomjs.binary.path", "phantomjs.exe");
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability("takesScreenshot", false);
PhantomJSDriver driver = new PhantomJSDriver(caps);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get(new URL("..."));
String result = driver.getPageSource();
Run Code Online (Sandbox Code Playgroud)
Update2: 我现在手动渲染我的页面,因为Google抓取工具现在呈现Angular网站
根据http://getbootstrap.com/javascript/#dropdowns事件(例如,show.bs.dropdown,hide.bs.dropdown)在打开/关闭drowdown时抛出.这有效直到模块bootstrap-ui处于活动状态.我创建了一个显示问题http://plnkr.co/edit/luYpweQZx22IkWHeMKhM的plunkr .当删除对ui.boostrap的依赖时,抛出事件,即
var app = angular.module('myapp', ['ui.bootstrap']);
Run Code Online (Sandbox Code Playgroud)
被替换为
var app = angular.module('myapp', []);
Run Code Online (Sandbox Code Playgroud)
版本是:Bootstrap 3.0.3,Angular 1.2.4(也用1.2.13测试),Angular UI Bootstrap 0.10.0,JQuery 2.0.3
似乎是bootstrap-ui中的一个错误,任何解决方法的想法?
在 Spring boot + MongoDB 应用程序中,我正在尝试为电子邮件字段创建唯一索引。
@Document
public class User {
@Id
private String id;
@Indexed(unique = true)
private String email;
}
Run Code Online (Sandbox Code Playgroud)
public interface UserRepository extends MongoRepository<User, String>
Run Code Online (Sandbox Code Playgroud)
但是我仍然可以使用相同的电子邮件插入两个用户对象,所以
userRepository.save(new User("my@email.com"))
userRepository.save(new User("my@email.com"))
Run Code Online (Sandbox Code Playgroud)
在用户集合中创建两个条目。
我究竟做错了什么?
我知道Spring Data MongoDB - 在哪里以编程方式为 Mongo 集合创建索引?,但我正在寻找“仅注释”的解决方案。
angularjs ×3
javascript ×3
ajax ×1
angular-ui ×1
htmlunit ×1
java ×1
mongodb ×1
spring ×1
spring-boot ×1
state ×1
web-crawler ×1