我目前正在尝试概念化如何处理在另一个组件中的调度之后基于数据更改在组件中调度操作.
采取这种情况:
dispatch(someAjax)
- >状态更新中的属性.
在此之后,我需要另一个依赖于此相同属性的组件来知道已更新并根据新值调度操作.
而不是使用某种类型的value.on(change...
解决方案,处理这种类型的动作'级联'的首选方法是什么?
我真的只是在学习Angular,我正在尝试创建一个基于身份验证限制内容访问的应用程序.我有认证部分工作(也使用Laravel PHP框架),但我有一个问题"重新加载"基于身份验证状态的某些内容,即成功的身份验证后.
最初,我想要做的是在用户登录后更新主导航菜单.我确信有更好的方法,但到目前为止我所拥有的是从具有不同导航元素的服务器返回的视图,具体取决于是否用户是否登录,然后将其加载到包含ng-include的元素中.
可以选择登录,将登录表单加载到ng-view中.用户登录后,我想用服务器的视图刷新ng-include.
有没有办法在成功登录后在ng-include中重新加载该模板?
如果这是错误的方法,请随时推荐更好的解决方法.当然,这在jQuery中很容易做到,但我更喜欢用Angular方式做事.
这是我目前的一些代码:
index.html的:
<div class="container" ng-controller="appController">
<div id="nav" ng-include src="menuUrl()"></div>
<div class="row">
<div class="span3" ng-include src="'partials/brands.html'" ng-controller="brandController"></div>
<div class="span9" ng-view></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
一些控制器:
.controller('appController', function($scope){
$scope.loggedIn = false;
$scope.menuUrl = function() {
return "partials/nav.html";
};
})
.controller('loginController',function($scope, $sanitize, $location, Authenticate, Flash){
$scope.login = function(){
Authenticate.save({
'email': $sanitize($scope.email),
'password': $sanitize($scope.password)
},function() {
$location.path('/products')
Flash.clear()
sessionStorage.authenticated = true;
},function(response){
Flash.show(response.flash)
})
}
})
.controller('logoutController',function($scope, $location, Authenticate, Flash){
$scope.logout = function (){
Authenticate.get({},function(response){
delete sessionStorage.authenticated
Flash.show(response.flash)
$location.path('/login')
}) …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Eloquent来获取具有brand_id
映射到brands
表的列的特定产品,该brand
数组将返回空白.
这里有什么明显的东西需要改变吗?
$product = Product::with('images')->with('brand')->select($fields)->where('display', '=', 1)->find($id);
Run Code Online (Sandbox Code Playgroud)
//产品型号
class Product extends Eloquent {
...
public function brand()
{
return $this->belongsTo('Brand');
}
Run Code Online (Sandbox Code Playgroud)
//品牌模型
class Brand extends Eloquent {
...
public function products()
{
return $this->hasMany('Product');
}
Run Code Online (Sandbox Code Playgroud) 我想保存order
有order_items
,但我没有真正找到在文档的任何支持这种使用情况.一个hasMany关系.
基本上有一张orders
桌子id | user_id
和一张order_items
桌子id | order_id | product_id
.
如何同时save()
订购和使用一系列商品而无需循环遍历商品并单独保存?
这可能吗?
伪代码假设$items
是一个数组:
$items = Session::get("cart.items");
$order = new Order;
$order->user_id = Auth::user()->id;
$order->order_items = $items;
$order->save();
Run Code Online (Sandbox Code Playgroud) 我试图在控制器中使用一个函数来返回数据,这样我就可以在应用程序中重用该函数来调用数据并偶尔刷新它.
我的代码看起来是正确的,但实际上,在每次加载时都会崩溃浏览器.
我能够通过使用E指令然后将元素放在部分中来使其工作,但这不能实现我所需要的.
最终,我想做这样的事情:
<div ng-repeat="user in getListUsers()">{{ user.somedata }}</div>
Run Code Online (Sandbox Code Playgroud)
我已经尝试了各种各样的东西让它在测试中工作,包括将$ http放在控制器中,所有都具有相同的结果.
如果我在控制器方法中分配一个变量而不是返回数据,那可行,但是我需要在控制器中调用该方法,我不希望它默认运行.只是想在需要时在模板中进行调用.
任何帮助弄清楚为什么这不起作用将是伟大的.谢谢.
这就是我的功能......
elite.controller('UserController', function($scope, User){
$scope.getListUsers = function(){
User.listUsers().then(function(response){
return response.users;
});
}
});
elite.factory('User', function($http){
var User = {
getUser: function(id){
return $http.get('/user/' + id + '/settings').then(function(response){
return response.data;
});
},
listUsers: function(){
return $http.get('/user/').then(function(response){
return response.data;
});
}
}
return User;
});
Run Code Online (Sandbox Code Playgroud)
编辑:
使用下面的一些想法,我能够以不同的方式获得我想要的功能.基本上,我希望数据按需加载,而不是预先加载,因为我试图将该控制器中的所有用户逻辑分组,并且我不希望为每个用户加载完整数据.我暂时使用$ rootScope,直到我找出一些范围继承问题,因为使用$ scope.users在模板中以空值结束.我可以看到AJAX呼叫回来,但不知道它在哪里,但这是另一个问题.
elite.controller('UserController', function($scope, $rootScope, User){
$scope.getListUsers = function(){
User.listUsers().then(function(response){
$rootScope.users = response.users;
});
};
});
Run Code Online (Sandbox Code Playgroud)
在nav元素中我有这个:
<div ng-controller="UserController">
<a ng-href="/#user/list" …
Run Code Online (Sandbox Code Playgroud) 我一直在寻找是否有一种方法可以使用Laravel的工匠为本地开发模拟SSL而无需运气.
这是可能的,如果是的话,怎么样?
我知道这是一个非常普遍的问题,但我在搜索中没有看到任何相关内容.
我试图让FancyBox加载包含表单的文件.我想使用jQuery Validate插件进行验证,但在进行回调之前,表单没有被添加到DOM中.
afterLoad选项确实会打开一个警报,但它实际上会在加载ajax内容之前打开.
我可以在加载的文件中添加一个href,当点击它时运行validate(),但有趣的是,它只有在我通过ID而不是类调用表单时才有效,因为在该类的同一页面上有另一个表单.
我有以下代码:
<a href="/url" class="fancy fancybox.ajax">link</a></li>
$(".fancy").fancybox({
maxWidth : 800,
maxHeight : 600,
fitToView : false,
width : '70%',
height : '70%',
autoSize : false,
closeClick : false,
openEffect : 'none',
closeEffect : 'none',
afterLoad: function() {
//$(".validateMe").validate();
alert(987987);
}
});
<form id="someId" action="javascript:someFunction();" class="validateMe" method="post">
Run Code Online (Sandbox Code Playgroud) 我正在设置我的第一个Laravel 4应用程序,规范要求id字段为varchar(36)并且是UUID.
使用Eloquent,我对示例表的迁移如下所示:
Schema::create('users', function($table)
{
$table->string('id', 36)->primary;
$table->string('first_name', 50);
$table->string('last_name', 50);
$table->string('email')->unique();
$table->string('password', 60);
$table->timestamps();
$table->softDeletes();
});
Run Code Online (Sandbox Code Playgroud)
创建users表时,id字段未定义为PK或唯一.它被定义为varchar(36)NOT NULL.
为什么在我运行迁移时会发生这种情况?
我最初的问题是关于使用UUID,但我有意识地通过将此添加到我的Users模型解决了以防其他人看到此帖子:
protected $hidden = array('password');
protected $fillable = array('id', 'first_name', 'last_name', 'email', 'password');
Run Code Online (Sandbox Code Playgroud)
这是我添加用户的路径(我使用的函数来创建UUID):
Route::post('signup', function()
{
$userdata = array(
'id' => gen_uuid(),
'first_name' => Input::get('first_name'),
'last_name' => Input::get('last_name'),
'email' => Input::get('email'),
'password' => Hash::make(Input::get('password'))
);
$user = new User($userdata);
$user->save();
return View::make('login/login')->with('userdata', $userdata);
});
Run Code Online (Sandbox Code Playgroud) 处理表单以供用户根据$ rootScope上的变量编辑其详细信息(也可以是$ scope).
$rootScope.formData = $rootScope.user;
Run Code Online (Sandbox Code Playgroud)
在视图中,输入上有一个ng模型:
ng-model="formData.email"
Run Code Online (Sandbox Code Playgroud)
我期望的行为是更新模型,只有$ rootScope.formData会更新,而是更新.
有没有办法打破两者之间的关系?
我在一个使用哈希监听器的站点上工作,以显示和隐藏内容DIV并滚动到同名的命名锚点.
我有一个奇怪的问题,它不是滚动到锚点,而是滚动到DIV,其ID与锚点的名称相同.
一旦我将DIV ID更改为不同的内容,行为就像预期的那样.
我似乎无法找到任何关于此的文档,并且想知道这是否是记录在案的行为.
有效的代码:
<a name="top">top</a>
<p id="bottomx" style="height: 1800px;">
<a href="#top">top</a>
<a href="#bottom">bottom</a>
<br>
</p>
<a name="bottom">bottom</a>
Run Code Online (Sandbox Code Playgroud)
没有按预期工作:
<a name="top">top</a>
<p id="bottom" style="height: 1800px;">
<a href="#top">top</a>
<a href="#bottom">bottom</a>
<br>
</p>
<a name="bottom">bottom</a>
Run Code Online (Sandbox Code Playgroud)
在第二个例子中,它将滚动到名为"bottom"的P.同样,如果我在页面底部创建一个ID为"bottom"的DIV,并且我点击了page.html#bottom,它会向下滚动到那个DIV.
看起来很混乱.知道为什么这样做?Safari和FF中的行为相同.