我一直在关注本地状态的Apollo Client文档。
我实现了一个非常简单的客户端缓存查询:
export const GET_USER_ACCOUNTS = gql`
query GetUserAccounts {
userAccounts @client
name @client
}
`;
Run Code Online (Sandbox Code Playgroud)
userAccounts并name在身份验证后都存储在我的缓存中:
export const GET_USER_ACCOUNTS = gql`
query GetUserAccounts {
userAccounts @client
name @client
}
`;
Run Code Online (Sandbox Code Playgroud)
并且我已经使用默认值预热了缓存:
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';
const cache = new InMemoryCache();
const link = new HttpLink({
uri: 'http://localhost:8002/v1/graphql',
headers: {
Authorization: `${localStorage.getItem('token')}`,
},
});
const client = new ApolloClient({
cache, …Run Code Online (Sandbox Code Playgroud) 在Angular 1中,您可以使用&将函数作为参数传递给属性指令.我知道你可以使用函数将函数作为输入传递给Angular 2中的元素指令(组件)
<custom-component [callback]="myCallbackFuncton">
..etc
</custom-component>
Run Code Online (Sandbox Code Playgroud)
语法,但有没有办法只使用属性指令?我只能得到一个字符串(它允许我在范围内查看该函数),但更愿意一次性传递该函数.所以我希望能够在我的模板中写出这样的东西
<form custom-submit="ctrl.register">
...etc
</form>
Run Code Online (Sandbox Code Playgroud)
并在指令js中,
@Directive({
selector: '[custom-submit]',
})
@Inject('$element', '$attrs')
export default class CustomSubmit {
constructor($element, $scope, $attrs) {
this.$element = $element;
$element[0].addEventListener('submit', () => {
// custom validation behaviour
$attrs.customSubmit();
});
}
}
Run Code Online (Sandbox Code Playgroud)
而不是必须写像
$scope.ctrl[$attrs.customSubmit]()
Run Code Online (Sandbox Code Playgroud)