如何设置可在所有视图中访问的全局函数?
在app.component.ts中我添加了一个简单的方法
openShare() {console.log("button clicked")}
Run Code Online (Sandbox Code Playgroud)
然后在我的导航中我有
<button ion-button right (click)="openShare()">
<ion-icon name="md-share"></ion-icon>
</button>
Run Code Online (Sandbox Code Playgroud)
当我尝试从任何页面访问它时,我得到以下内容.
self.context.openShare is not a function
Run Code Online (Sandbox Code Playgroud)
但是,如果我将它直接放在构造函数中(例如this.openShare();),它确实执行正常,但是当使用(单击)函数从任何页面调用时它只是不起作用.
app.component.ts不是全局的吗?我认为这是我放置的地方,但也许我错过了一些东西.
基本上它是导航器上一个简单按钮的功能,我需要它是全局的,因为它在每个页面上使用.
任何帮助将不胜感激,仍然可以计算Ionic 2.
我看了一些例子,但似乎无法弄清楚这一点。基本上,我在 ionic 应用程序中有一个联系表,允许用户联系列表所有者。
当他们提交表单时,我想将广告 ID 存储在本地存储中,以便他们无法重复提交。
我需要能够存储 json 数组,然后检查结果。如果广告 ID 在会话存储中,则不要显示表单,否则显示它。
我目前正在这样做,它似乎将广告 ID 存储在一个数组中,但是如何循环检查 ID 是否存在?我尝试了 angular forEach,但结果是一个对象。
// Parse any JSON previously stored in allEntries
var existingEntries = JSON.parse(localStorage.getItem("store_owner_ad_contacts"));
if(existingEntries == null) existingEntries = [];
var adId = {
"id":$scope.adId
};
// Save allEntries back to local storage
existingEntries.push(adId);
localStorage.setItem("store_owner_ad_contacts", JSON.stringify(existingEntries));
var values = JSON.parse(localStorage.getItem("store_owner_ad_contacts"));
angular.forEach(values, function(value, key) {
// ^ This is coming as an object how can I get the key value?
if(value == adId){
//form has …Run Code Online (Sandbox Code Playgroud) 在Mamp Pro 4中不可能同时拥有http和https吗?我正在处理的应用程序需要取决于页面.
我必须遗漏一些东西,因为当我启用SSL时,没有任何意义,只有https工作,http然后停止工作.
我试过浏览http.conf,但真的不知道是什么引起了这个.
我认为它只为https生成vhost,然后删除http.甚至看起来你不能手动编辑它.
任何建议都会很棒.
我有一个国家数据库和另一个名为区域的表.
Countries
[id, name, status (1 enabled 0 disabled) ]
Zones
[id, name, country_id]
Run Code Online (Sandbox Code Playgroud)
我使用以下查询来匹配所有国家/地区的区域.
select
z.name as state,
z.id as state_id,
c.name as country_name,
c.id as country_id,
c.status as country_status
from countries c left join zones z on c.id = z.country_id
Run Code Online (Sandbox Code Playgroud)
所以基本上简而言之,区域是状态,输出就是这样.
+-----------------------------------------------------+----------+--- -----------------------------------------+------------+----------------+
| state | state_id | country_name | country_id | country_status |
+-----------------------------------------------------+----------+--- -----------------------------------------+------------+----------------+
| NULL | NULL | Christmas Island | 45 | 1
| NULL | NULL | Puerto Rico | 172 | 1 …Run Code Online (Sandbox Code Playgroud) angular ×1
angularjs ×1
ionic2 ×1
ionic3 ×1
javascript ×1
mamp ×1
mamp-pro ×1
mysql ×1
php ×1
typescript ×1