有条件地在角度指令中加载模板

时间:2016-09-20 08:30:46

标签: javascript angularjs angularjs-directive

我试图仅有条件地加载指令模板,例如 -

func isInternetAvailable() -> Bool {

    var zeroAddress = sockaddr_in()
    zeroAddress.sin_len = UInt8(MemoryLayout<sockaddr_in>.size)
    zeroAddress.sin_family = sa_family_t(AF_INET)

    guard let defaultRouteReachability = withUnsafePointer(to: &zeroAddress, {
        $0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
            SCNetworkReachabilityCreateWithAddress(nil, $0)
        }
    }) else {
        return false
    }

    var flags: SCNetworkReachabilityFlags = []
    if !SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags) {
        return false
    }

    let isReachable = flags.contains(.reachable)
    let needsConnection = flags.contains(.connectionRequired)

    return (isReachable && !needsConnection)
}

无论如何都能实现这个目标吗?

2 个答案:

答案 0 :(得分:0)

/*This will solve you problem*/


link: ...
templateUrl: function() {
    if(shouldBetruncated) {
        return 'template/truncate.html';
    } else {
        return '';
    }
}

有关详细信息,您可以从html传递模板或根据条件生成

答案 1 :(得分:0)

试试这个......

split(/\s|,/,"Reporting EXE1 BASE,Normal")

} }]);